These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Firesphere\PartialUserforms\Extensions; |
||
4 | |||
5 | use Firesphere\PartialUserforms\Jobs\PartialSubmissionJob; |
||
6 | use Firesphere\PartialUserforms\Services\DateService; |
||
7 | use SilverStripe\Core\Injector\Injector; |
||
8 | use SilverStripe\Forms\CheckboxField; |
||
9 | use SilverStripe\Forms\EmailField; |
||
10 | use SilverStripe\Forms\FieldList; |
||
11 | use SilverStripe\Forms\Tab; |
||
12 | use SilverStripe\Forms\TextField; |
||
13 | use SilverStripe\ORM\DataExtension; |
||
14 | use SilverStripe\ORM\FieldType\DBDatetime; |
||
15 | use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor; |
||
16 | use Symbiote\QueuedJobs\Services\QueuedJobService; |
||
17 | |||
18 | /** |
||
19 | * Class SiteConfigExtension |
||
20 | * |
||
21 | * @package Firesphere\PartialUserforms\Extensions |
||
22 | * @property \SilverStripe\SiteConfig\SiteConfig|\Firesphere\PartialUserforms\Extensions\SiteConfigExtension $owner |
||
23 | * @property boolean $SendDailyEmail |
||
24 | * @property boolean $CleanupAfterSend |
||
25 | * @property string $SendMailTo |
||
26 | * @property string $SendMailFrom |
||
27 | */ |
||
28 | class SiteConfigExtension extends DataExtension |
||
29 | { |
||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private static $db = [ |
||
0 ignored issues
–
show
|
|||
34 | 'SendDailyEmail' => 'Boolean(false)', |
||
35 | 'CleanupAfterSend' => 'Boolean(false)', |
||
36 | 'SendMailTo' => 'Varchar(255)', |
||
37 | 'SendMailFrom' => 'Varchar(255)', |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * @param FieldList $fields |
||
42 | */ |
||
43 | public function updateCMSFields(FieldList $fields) |
||
44 | { |
||
45 | $fields->addFieldToTab('Root', Tab::create('PartialUserFormSubmissions')); |
||
46 | |||
47 | $fields->addFieldsToTab('Root.PartialUserFormSubmissions', [ |
||
48 | CheckboxField::create( |
||
49 | 'SendDailyEmail', |
||
50 | _t(__CLASS__ . '.SendDailyEmail', 'Send partial submissions daily') |
||
51 | ), |
||
52 | CheckboxField::create( |
||
53 | 'CleanupAfterSend', |
||
54 | _t(__CLASS__ . '.CleanupAfterSend', 'Remove partial submissions after sending') |
||
55 | ), |
||
56 | $emailField = TextField::create( |
||
57 | 'SendMailTo', |
||
58 | _t(__CLASS__ . '.SendMailTo', 'Email address the partial submissions should be send to') |
||
59 | ), |
||
60 | EmailField::create( |
||
61 | 'SendMailFrom', |
||
62 | _t(__CLASS__ . '.SendMailFrom', 'Email address from which the partial submissions should be send') |
||
63 | ) |
||
64 | ]); |
||
65 | |||
66 | $emailField->setDescription(_t(__CLASS__ . '.EmailDescription', 'Can be a comma separated set of addresses')); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @throws \Exception |
||
71 | */ |
||
72 | public function onAfterWrite() |
||
73 | { |
||
74 | parent::onAfterWrite(); |
||
75 | |||
76 | if ($this->owner->SendDailyEmail && !empty($this->owner->SendMailTo)) { |
||
77 | $jobs = QueuedJobDescriptor::get()->filter([ |
||
78 | 'Implementation' => PartialSubmissionJob::class, |
||
79 | 'StartAfter:GreaterThan' => DBDatetime::now() |
||
80 | ]); |
||
81 | // Only create a new job if there isn't one already |
||
82 | if ((int)$jobs->count() === 0) { |
||
83 | $job = Injector::inst()->get(PartialSubmissionJob::class); |
||
84 | /** @var QueuedJobService $queuedJob */ |
||
85 | $queuedJob = Injector::inst()->get(QueuedJobService::class); |
||
86 | $dbDateTime = DateService::getTomorrow(); |
||
87 | $queuedJob->queueJob($job, $dbDateTime->Format(DBDatetime::ISO_DATETIME)); |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 |
This check marks private properties in classes that are never used. Those properties can be removed.