1 | <?php |
||
2 | |||
3 | namespace PhpTek\Exodus\Model; |
||
4 | |||
5 | use PhpTek\Exodus\Model\FailedURLRewriteObject; |
||
6 | use PhpTek\Exodus\Model\FailedURLRewriteSummary; |
||
7 | use SilverStripe\Core\Injector\Injectable; |
||
8 | use SilverStripe\ORM\DataObject; |
||
9 | use SilverStripe\ORM\FieldType\DBDatetime; |
||
10 | use SilverStripe\Security\Member; |
||
11 | use SilverStripe\Security\Security; |
||
12 | |||
13 | /** |
||
14 | * Caches some metadata for each import. Allows imports to have a DataObject-like functionality. |
||
15 | * |
||
16 | * @author Russell Michell <[email protected]> |
||
17 | * @package phptek/silverstripe-exodus |
||
18 | * @see {@link StaticSiteImporter} |
||
19 | */ |
||
20 | class StaticSiteImportDataObject extends DataObject |
||
21 | { |
||
22 | use Injectable; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private static $table_name = 'StaticSiteImportDataObject'; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
28 | |||
29 | /** |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private static $db = [ |
||
0 ignored issues
–
show
|
|||
34 | 'Ended' => DBDatetime::class, |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | private static $has_one = [ |
||
0 ignored issues
–
show
|
|||
42 | 'User' => Member::class, |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * Get the most recently started/run import. |
||
47 | * |
||
48 | * @param Member $member |
||
49 | * @return null | DataList |
||
0 ignored issues
–
show
The type
PhpTek\Exodus\Model\DataList was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
50 | */ |
||
51 | public static function current($member = null) |
||
52 | { |
||
53 | $import = StaticSiteImportDataObject::get() |
||
54 | ->sort('Created') |
||
55 | ->last(); |
||
56 | |||
57 | if ($import && $member) { |
||
58 | return $import->filter('UserID', $member->ID); |
||
59 | } |
||
60 | |||
61 | return $import; |
||
0 ignored issues
–
show
|
|||
62 | } |
||
63 | |||
64 | /** |
||
65 | * To be called at the start of an import. |
||
66 | * |
||
67 | * @return StaticSiteImportDataObject |
||
68 | */ |
||
69 | public function start() |
||
70 | { |
||
71 | $this->UserID = Security::getCurrentUser()->getField('ID'); |
||
0 ignored issues
–
show
|
|||
72 | $this->write(); |
||
73 | |||
74 | return $this; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * To be called at the end of an import. |
||
79 | * |
||
80 | * @return StaticSiteImportDataObject |
||
81 | */ |
||
82 | public function end() |
||
83 | { |
||
84 | $this->Ended = DBDatetime::now()->getValue(); |
||
0 ignored issues
–
show
|
|||
85 | $this->write(); |
||
86 | |||
87 | return $this; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Make sure related FailedURLRewriteObject's are also removed |
||
92 | * |
||
93 | * @todo Would belongs_to() do the job? |
||
94 | * @return void |
||
95 | */ |
||
96 | public function onAfterDelete() |
||
97 | { |
||
98 | parent::onAfterDelete(); |
||
99 | |||
100 | $relatedFailedRewriteObjects = DataObject::get(FailedURLRewriteObject::class)->filter('ImportID', $this->ID); |
||
101 | $relatedFailedRewriteSummaries = DataObject::get(FailedURLRewriteSummary::class)->filter('ImportID', $this->ID); |
||
102 | |||
103 | $relatedFailedRewriteObjects->each(function ($item) { |
||
104 | $item->delete(); |
||
105 | }); |
||
106 | |||
107 | $relatedFailedRewriteSummaries->each(function ($item) { |
||
108 | $item->delete(); |
||
109 | }); |
||
110 | } |
||
111 | } |
||
112 |