Browse code

Update

Benjamin Roth authored on26/07/2023 15:18:55
Showing11 changed files
... ...
@@ -7,3 +7,10 @@ services:
7 7
     vonRotenberg\MemberfilesBundle\:
8 8
         resource: ../src
9 9
         exclude: ../src/{VonrotenbergMemberfilesBundle.php,ContaoManager,Entity,Migrations,Model,Resources,Tests,Widget}
10
+
11
+    vonrotenberg.cron.secure_downloads_service:
12
+        class: vonRotenberg\MemberfilesBundle\Cron\SecureDownloadsJob
13
+        public: true
14
+        arguments:
15
+            - "@database_connection"
16
+            - "@logger"
... ...
@@ -10,4 +10,37 @@
10 10
 
11 11
 use vonRotenberg\MemberfilesBundle\Model\SecureDownloadsModel;
12 12
 
13
+/**
14
+ * Notification types
15
+ */
16
+$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['contao']['secDownloads_submitted'] = array
17
+(
18
+    'recipients'    => array
19
+    (
20
+        'member_email' // The email address of the recipient
21
+    ),
22
+    'email_text'    => array
23
+    (
24
+        'member_firstname', // The firstname of the recipient
25
+        'member_lastname', // The lastname of the recipient
26
+        'downloads' // The names of all new files
27
+    ),
28
+    'email_html'    => array
29
+    (
30
+        'member_firstname', // The firstname of the recipient
31
+        'member_lastname', // The lastname of the recipient
32
+        'downloads_html', // The names of all new files
33
+    )
34
+);
35
+
36
+/**
37
+ * Permissions
38
+ */
39
+
40
+$GLOBALS['TL_PERMISSIONS'][] = 'sec_dl_access';
41
+
42
+/**
43
+ * Models
44
+ */
45
+
13 46
 $GLOBALS['TL_MODELS']['tl_member_secureDownloads'] = SecureDownloadsModel::class;
... ...
@@ -15,13 +15,15 @@ use Contao\CoreBundle\DataContainer\PaletteManipulator;
15 15
  */
16 16
 
17 17
 PaletteManipulator::create()
18
-    ->addLegend('sec_dl_legend','publish_legend',PaletteManipulator::POSITION_BEFORE)
19
-    ->addField('secureDownloadsEnabled','sec_dl_legend',PaletteManipulator::POSITION_APPEND)
20
-    ->applyToPalette('root','tl_page')
21
-    ->applyToPalette('rootfallback','tl_page');
18
+    ->addLegend('sec_dl_legend', 'publish_legend', PaletteManipulator::POSITION_BEFORE)
19
+    ->addField('secureDownloadsEnabled', 'sec_dl_legend', PaletteManipulator::POSITION_APPEND)
20
+    ->applyToPalette('root', 'tl_page')
21
+    ->applyToPalette('rootfallback', 'tl_page');
22 22
 
23 23
 $GLOBALS['TL_DCA']['tl_page']['palettes']['__selector__'][] = 'secureDownloadsEnabled';
24
-$GLOBALS['TL_DCA']['tl_page']['subpalettes']['secureDownloadsEnabled'] = 'secureDownloadsSRC,secureDownloadsTarget,secureDownloadsRegExp,secureDownloadsFields,sd_nc_enable,sd_nc_notification';
24
+$GLOBALS['TL_DCA']['tl_page']['palettes']['__selector__'][] = 'sd_nc_enable';
25
+$GLOBALS['TL_DCA']['tl_page']['subpalettes']['secureDownloadsEnabled'] = 'secureDownloadsSRC,secureDownloadsTarget,secureDownloadsRegExp,secureDownloadsFields,sd_nc_enable';
26
+$GLOBALS['TL_DCA']['tl_page']['subpalettes']['sd_nc_enable'] = 'sd_nc_notification';
25 27
 
26 28
 
27 29
 /**
... ...
@@ -29,64 +31,55 @@ $GLOBALS['TL_DCA']['tl_page']['subpalettes']['secureDownloadsEnabled'] = 'secure
29 31
  */
30 32
 $GLOBALS['TL_DCA']['tl_page']['fields']['secureDownloadsEnabled'] = array
31 33
 (
32
-  'label'                   => &$GLOBALS['TL_LANG']['tl_page']['secureDownloadsEnabled'],
33
-  'exclude'                 => true,
34
-  'inputType'               => 'checkbox',
35
-  'eval'                    => array('submitOnChange'=>true),
36
-  'sql'                     => "char(1) NOT NULL default ''"
34
+    'exclude' => true,
35
+    'inputType' => 'checkbox',
36
+    'eval' => array('submitOnChange' => true),
37
+    'sql' => "char(1) NOT NULL default ''"
37 38
 );
38 39
 $GLOBALS['TL_DCA']['tl_page']['fields']['secureDownloadsSRC'] = array
39 40
 (
40
-    'label'                   => &$GLOBALS['TL_LANG']['tl_page']['secureDownloadsSRC'],
41
-    'exclude'                 => true,
42
-    'inputType'               => 'fileTree',
43
-    'eval'                    => array('mandatory'=>true,'fieldType'=>'radio', 'tl_class'=>'clr'),
44
-    'sql'                     => 'binary(16) NULL'
41
+    'exclude' => true,
42
+    'inputType' => 'fileTree',
43
+    'eval' => array('mandatory' => true, 'fieldType' => 'radio', 'tl_class' => 'clr'),
44
+    'sql' => 'binary(16) NULL'
45 45
 );
46 46
 
47 47
 $GLOBALS['TL_DCA']['tl_page']['fields']['secureDownloadsTarget'] = array
48 48
 (
49
-  'label'                   => &$GLOBALS['TL_LANG']['tl_page']['secureDownloadsTarget'],
50
-  'exclude'                 => true,
51
-  'inputType'               => 'fileTree',
52
-  'eval'                    => array('mandatory'=>true,'fieldType'=>'radio', 'tl_class'=>'clr'),
53
-  'sql'                     => 'binary(16) NULL'
49
+    'exclude' => true,
50
+    'inputType' => 'fileTree',
51
+    'eval' => array('mandatory' => true, 'fieldType' => 'radio', 'tl_class' => 'clr'),
52
+    'sql' => 'binary(16) NULL'
54 53
 );
55 54
 
56 55
 $GLOBALS['TL_DCA']['tl_page']['fields']['secureDownloadsRegExp'] = array
57 56
 (
58
-  'label'                   => &$GLOBALS['TL_LANG']['tl_page']['secureDownloadsRegExp'],
59
-  'exclude'                 => true,
60
-  'inputType'               => 'text',
61
-  'eval'                    => array('mandatory'=>true,'maxlength'=>64,'preserveTags'=>true,'decodeEntities'=>true),
62
-  'sql'                     => 'varchar(64) NULL'
57
+    'exclude' => true,
58
+    'inputType' => 'text',
59
+    'eval' => array('mandatory' => true, 'maxlength' => 64, 'preserveTags' => true, 'decodeEntities' => true),
60
+    'sql' => 'varchar(64) NULL'
63 61
 );
64 62
 
65 63
 $GLOBALS['TL_DCA']['tl_page']['fields']['secureDownloadsFields'] = array
66 64
 (
67
-  'label'                   => &$GLOBALS['TL_LANG']['tl_page']['secureDownloadsFields'],
68
-  'exclude'                 => true,
69
-  'inputType'               => 'checkboxWizard',
70
-  'options_callback'        => array('tl_page_eSM_secureDownloads','getMemberProperties'),
71
-  'eval'                    => array('mandatory'=>true,'multiple'=>true),
72
-  'sql'                     => 'varchar(255) NULL'
65
+    'exclude' => true,
66
+    'inputType' => 'checkboxWizard',
67
+    'eval' => array('mandatory' => true, 'multiple' => true),
68
+    'sql' => 'varchar(255) NULL'
73 69
 );
74 70
 
75 71
 $GLOBALS['TL_DCA']['tl_page']['fields']['sd_nc_enable'] = array
76 72
 (
77
-  'label'                   => &$GLOBALS['TL_LANG']['tl_page']['sd_nc_enable'],
78
-  'exclude'                 => true,
79
-  'inputType'               => 'checkbox',
80
-  'eval'                    => array('tl_class'=>'w50 m12','submitOnChange'=>true),
81
-  'sql'                     => "char(1) NOT NULL default ''"
73
+    'exclude' => true,
74
+    'inputType' => 'checkbox',
75
+    'eval' => array('tl_class' => 'w50 m12', 'submitOnChange' => true),
76
+    'sql' => "char(1) NOT NULL default ''"
82 77
 );
83 78
 
84 79
 $GLOBALS['TL_DCA']['tl_page']['fields']['sd_nc_notification'] = array
85 80
 (
86
-  'label'                     => &$GLOBALS['TL_LANG']['tl_page']['sd_nc_enable'],
87
-  'exclude'                   => true,
88
-  'inputType'                 => 'select',
89
-  'options_callback'          => array('tl_page_eSM_secureDownloads', 'getNotificationChoices'),
90
-  'eval'                      => array('mandatory'=>true,'includeBlankOption'=>true, 'chosen'=>true, 'tl_class'=>'w50'),
91
-  'sql'                       => "int(10) unsigned NOT NULL default '0'"
81
+    'exclude' => true,
82
+    'inputType' => 'select',
83
+    'eval' => array('mandatory' => true, 'includeBlankOption' => true, 'chosen' => true, 'tl_class' => 'w50'),
84
+    'sql' => "int(10) unsigned NOT NULL default '0'"
92 85
 );
... ...
@@ -16,8 +16,8 @@ use Contao\CoreBundle\DataContainer\PaletteManipulator;
16 16
 PaletteManipulator::create()
17 17
     ->addLegend('sec_dl_legend','account_legend',PaletteManipulator::POSITION_BEFORE)
18 18
     ->addField('sec_dl_access','sec_dl_legend',PaletteManipulator::POSITION_APPEND)
19
-    ->applyToPalette('extend')
20
-    ->applyToPalette('custom');
19
+    ->applyToPalette('extend','tl_user')
20
+    ->applyToPalette('custom','tl_user');
21 21
 
22 22
 
23 23
 /**
... ...
@@ -16,7 +16,7 @@ use Contao\CoreBundle\DataContainer\PaletteManipulator;
16 16
 PaletteManipulator::create()
17 17
     ->addLegend('sec_dl_legend','alexf_legend',PaletteManipulator::POSITION_BEFORE)
18 18
     ->addField('sec_dl_access','sec_dl_legend',PaletteManipulator::POSITION_APPEND)
19
-    ->applyToPalette('default');
19
+    ->applyToPalette('default', 'tl_user');
20 20
 
21 21
 /**
22 22
  * Add fields to tl_user_group
... ...
@@ -21,6 +21,10 @@ $GLOBALS['TL_LANG']['tl_page']['secureDownloadsRegExp'][0] = 'Automatisierungs-F
21 21
 $GLOBALS['TL_LANG']['tl_page']['secureDownloadsRegExp'][1] = 'Regulärer Ausdruck um ein oder mehrere Zuordnungsfragmente aus dem Dateinamen zu extrahieren.';
22 22
 $GLOBALS['TL_LANG']['tl_page']['secureDownloadsFields'][0] = 'Fragment-Felder';
23 23
 $GLOBALS['TL_LANG']['tl_page']['secureDownloadsFields'][1] = 'Felder welche den Fragmenten zugeordnet werden.';
24
+$GLOBALS['TL_LANG']['tl_page']['sd_nc_enable'][0] = 'Benachrichtigung senden';
25
+$GLOBALS['TL_LANG']['tl_page']['sd_nc_enable'][1] = 'Sendet eine Benachrichtigung bei neuen Dateien.';
26
+$GLOBALS['TL_LANG']['tl_page']['sd_nc_notification*'][0] = 'Benachrichtigung';
27
+$GLOBALS['TL_LANG']['tl_page']['sd_nc_notification*'][1] = 'Die Benachrichtigung, welche gesendet werden soll.';
24 28
 
25 29
 /**
26 30
  * Legends
27 31
new file mode 100644
... ...
@@ -0,0 +1,48 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of eSales Media SinglereisenBundle
7
+ *
8
+ * (c) Benjamin Roth
9
+ *
10
+ * @license proprietary
11
+ */
12
+
13
+namespace vonRotenberg\MemberfilesBundle\Command;
14
+
15
+use Contao\CoreBundle\Framework\ContaoFramework;
16
+use Contao\System;
17
+use Symfony\Component\Console\Command\Command;
18
+use Symfony\Component\Console\Input\InputInterface;
19
+use Symfony\Component\Console\Output\OutputInterface;
20
+
21
+class SecureDownloadsCommand extends Command
22
+{
23
+    public function __construct(ContaoFramework $framework)
24
+    {
25
+        $this->framework = $framework;
26
+
27
+        parent::__construct();
28
+    }
29
+
30
+    protected function configure(): void
31
+    {
32
+        $this
33
+            ->setName('secureDownloads:sendNotifications')
34
+            ->setDescription('Sends notifications about newly added files.')
35
+        ;
36
+    }
37
+
38
+    protected function execute(InputInterface $input, OutputInterface $output): int
39
+    {
40
+        $this->framework->initialize();
41
+
42
+        $secdl_service = System::getContainer()->get("vonrotenberg.cron.secure_downloads_service");
43
+
44
+        $secdl_service->sendFileNotifications('cli');
45
+
46
+        return 0;
47
+    }
48
+}
0 49
new file mode 100644
... ...
@@ -0,0 +1,45 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of memberfiles bundle.
7
+ *
8
+ * (c) vonRotenberg
9
+ *
10
+ * @license commercial
11
+ */
12
+
13
+namespace vonRotenberg\MemberfilesBundle\Cron;
14
+
15
+use Contao\BackendUser;
16
+use Contao\Controller;
17
+use Contao\CoreBundle\ServiceAnnotation\Callback;
18
+use Contao\DataContainer;
19
+use Contao\System;
20
+use Doctrine\DBAL\Connection;
21
+use Psr\Log\LoggerInterface;
22
+
23
+class SecureDownloadsJob
24
+{
25
+
26
+    /** @var LoggerInterface */
27
+    private $logger;
28
+
29
+    /** @var Connection */
30
+    protected $db;
31
+
32
+    public function __construct(Connection $db, LoggerInterface $logger)
33
+    {
34
+        $this->logger = $logger;
35
+        $this->db = $db;
36
+    }
37
+
38
+    /**
39
+     * @CronJob("* * * * *")
40
+     */
41
+    public function sendFileNotifications(string $scope)
42
+    {
43
+
44
+    }
45
+}
... ...
@@ -38,7 +38,7 @@ class MemberListener {
38 38
     }
39 39
 
40 40
     /**
41
-     * @Callback(table="tl_member", target="list.operations.secureDownloads.button"
41
+     * @Callback(table="tl_member", target="list.operations.secureDownloads.button")
42 42
      */
43 43
     public function onListSecureDownloadsOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
44 44
     {
... ...
@@ -49,7 +49,7 @@ class MemberSecureDownloadsListener {
49 49
     }
50 50
 
51 51
     /**
52
-     * @Callback(table="tl_member_secureDownloads", target="list.operations.edit.button"
52
+     * @Callback(table="tl_member_secureDownloads", target="list.operations.edit.button")
53 53
      */
54 54
     public function onListEditOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
55 55
     {
... ...
@@ -68,7 +68,7 @@ class MemberSecureDownloadsListener {
68 68
     }
69 69
 
70 70
     /**
71
-     * @Callback(table="tl_member_secureDownloads", target="list.operations.delete.button"
71
+     * @Callback(table="tl_member_secureDownloads", target="list.operations.delete.button")
72 72
      */
73 73
     public function onListDeleteOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
74 74
     {
... ...
@@ -88,7 +88,7 @@ class MemberSecureDownloadsListener {
88 88
     }
89 89
 
90 90
     /**
91
-     * @Callback(table="tl_member_secureDownloads", target="list.operations.show.button"
91
+     * @Callback(table="tl_member_secureDownloads", target="list.operations.show.button")
92 92
      */
93 93
     public function onListShowOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
94 94
     {
... ...
@@ -31,7 +31,7 @@ class PageListener {
31 31
     }
32 32
 
33 33
     /**
34
-     * @Callback(table="tl_page", target="fields.secureDownloadsFields.options"
34
+     * @Callback(table="tl_page", target="fields.secureDownloadsFields.options")
35 35
      */
36 36
     public function onSecureDownloadsFieldsOptionsCallback(?DataContainer $dc)
37 37
     {
... ...
@@ -52,7 +52,7 @@ class PageListener {
52 52
     }
53 53
 
54 54
     /**
55
-     * @Callback(table="tl_page", target="fields.sd_nc_notification.options"
55
+     * @Callback(table="tl_page", target="fields.sd_nc_notification.options")
56 56
      */
57 57
     public function onSdNcNotificationOptionsCallback(?DataContainer $dc)
58 58
     {