33namespace Algolia \AlgoliaSearch \Model ;
44
55use Algolia \AlgoliaSearch \Api \Data \JobInterface ;
6+ use Magento \Framework \Data \Collection \AbstractDb ;
7+ use Magento \Framework \Exception \AlreadyExistsException ;
8+ use Magento \Framework \Model \Context ;
9+ use Magento \Framework \Model \ResourceModel \AbstractResource ;
10+ use Magento \Framework \ObjectManagerInterface ;
11+ use Magento \Framework \Registry ;
612
713/**
814 * @api
@@ -26,46 +32,33 @@ class Job extends \Magento\Framework\Model\AbstractModel implements JobInterface
2632{
2733 protected $ _eventPrefix = 'algoliasearch_queue_job ' ;
2834
29- /** @var \Magento\Framework\ObjectManagerInterface */
30- protected $ objectManager ;
31-
32- /**
33- * @param \Magento\Framework\Model\Context $context
34- * @param \Magento\Framework\Registry $registry
35- * @param \Magento\Framework\ObjectManagerInterface $objectManager
36- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
37- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
38- * @param array $data
39- */
4035 public function __construct (
41- \ Magento \ Framework \ Model \ Context $ context ,
42- \ Magento \ Framework \ Registry $ registry ,
43- \ Magento \ Framework \ ObjectManagerInterface $ objectManager ,
44- ?\ Magento \ Framework \ Model \ ResourceModel \ AbstractResource $ resource = null ,
45- ?\ Magento \ Framework \ Data \ Collection \ AbstractDb $ resourceCollection = null ,
46- array $ data = []
36+ Context $ context ,
37+ Registry $ registry ,
38+ protected ObjectManagerInterface $ objectManager ,
39+ ?AbstractResource $ resource = null ,
40+ ?AbstractDb $ resourceCollection = null ,
41+ array $ data = []
4742 ) {
4843 parent ::__construct ($ context , $ registry , $ resource , $ resourceCollection , $ data );
49-
50- $ this ->objectManager = $ objectManager ;
5144 }
5245
5346 /**
5447 * Magento Constructor
5548 *
5649 * @return void
5750 */
58- protected function _construct ()
51+ protected function _construct (): void
5952 {
60- $ this ->_init (\ Algolia \ AlgoliaSearch \ Model \ ResourceModel \Job::class);
53+ $ this ->_init (ResourceModel \Job::class);
6154 }
6255
6356 /**
64- * @throws \Magento\Framework\Exception\AlreadyExistsException
65- *
6657 * @return $this
58+ * @throws AlreadyExistsException|\Exception
59+ *
6760 */
68- public function execute ()
61+ public function execute (): Job
6962 {
7063 $ model = $ this ->objectManager ->get ($ this ->getClass ());
7164 $ method = $ this ->getMethod ();
@@ -83,7 +76,7 @@ public function execute()
8376 /**
8477 * @return $this
8578 */
86- public function prepare ()
79+ public function prepare (): Job
8780 {
8881 if ($ this ->getMergedIds () === null ) {
8982 $ this ->setMergedIds ([$ this ->getId ()]);
@@ -94,8 +87,8 @@ public function prepare()
9487
9588 $ this ->setDecodedData ($ decodedData );
9689
97- if (isset ($ decodedData ['store_id ' ])) {
98- $ this ->setStoreId ($ decodedData ['store_id ' ]);
90+ if (isset ($ decodedData ['storeId ' ])) {
91+ $ this ->setStoreId ($ decodedData ['storeId ' ]);
9992 }
10093 }
10194
@@ -108,7 +101,7 @@ public function prepare()
108101 *
109102 * @return bool
110103 */
111- public function canMerge (Job $ job , $ maxJobDataSize )
104+ public function canMerge (Job $ job , $ maxJobDataSize ): bool
112105 {
113106 if ($ this ->getClass () !== $ job ->getClass ()) {
114107 return false ;
@@ -124,44 +117,17 @@ public function canMerge(Job $job, $maxJobDataSize)
124117
125118 $ decodedData = $ this ->getDecodedData ();
126119
127- // @todo Remove legacy checks on 3.16.0
128- if ((!isset ($ decodedData ['product_ids ' ]) || count ($ decodedData ['product_ids ' ]) <= 0 )
129- && (!isset ($ decodedData ['category_ids ' ]) || count ($ decodedData ['category_ids ' ]) < 0 )
130- && (!isset ($ decodedData ['entity_ids ' ]) || count ($ decodedData ['entity_ids ' ]) < 0 )
131- && (!isset ($ decodedData ['page_ids ' ]) || count ($ decodedData ['page_ids ' ]) < 0 )) {
120+ if (!isset ($ decodedData ['entityIds ' ]) || count ($ decodedData ['entityIds ' ]) <= 0 ) {
132121 return false ;
133122 }
134123
135124 $ candidateDecodedData = $ job ->getDecodedData ();
136125
137- // @todo Remove legacy checks on 3.16.0
138- if ((!isset ($ candidateDecodedData ['product_ids ' ]) || count ($ candidateDecodedData ['product_ids ' ]) <= 0 )
139- && (!isset ($ candidateDecodedData ['category_ids ' ]) || count ($ candidateDecodedData ['category_ids ' ]) < 0 )
140- && (!isset ($ candidateDecodedData ['entity_ids ' ]) || count ($ candidateDecodedData ['entity_ids ' ]) < 0 )
141- && (!isset ($ candidateDecodedData ['page_ids ' ]) || count ($ candidateDecodedData ['page_ids ' ]) < 0 )) {
126+ if (!isset ($ candidateDecodedData ['entityIds ' ]) || count ($ candidateDecodedData ['entityIds ' ]) <= 0 ) {
142127 return false ;
143128 }
144129
145- // @todo Remove on 3.16.0
146- if (isset ($ decodedData ['product_ids ' ])
147- && count ($ decodedData ['product_ids ' ]) + count ($ candidateDecodedData ['product_ids ' ]) > $ maxJobDataSize ) {
148- return false ;
149- }
150-
151- // @todo Remove on 3.16.0
152- if (isset ($ decodedData ['category_ids ' ])
153- && count ($ decodedData ['category_ids ' ]) + count ($ candidateDecodedData ['category_ids ' ]) > $ maxJobDataSize ) {
154- return false ;
155- }
156-
157- // @todo Remove on 3.16.0
158- if (isset ($ decodedData ['page_ids ' ])
159- && count ($ decodedData ['page_ids ' ]) + count ($ candidateDecodedData ['page_ids ' ]) > $ maxJobDataSize ) {
160- return false ;
161- }
162-
163- if (isset ($ decodedData ['entity_ids ' ])
164- && count ($ decodedData ['entity_ids ' ]) + count ($ candidateDecodedData ['entity_ids ' ]) > $ maxJobDataSize ) {
130+ if (count ($ decodedData ['entityIds ' ]) + count ($ candidateDecodedData ['entityIds ' ]) > $ maxJobDataSize ) {
165131 return false ;
166132 }
167133
@@ -173,7 +139,7 @@ public function canMerge(Job $job, $maxJobDataSize)
173139 *
174140 * @return Job
175141 */
176- public function merge (Job $ mergedJob )
142+ public function merge (Job $ mergedJob ): Job
177143 {
178144 $ mergedIds = $ this ->getMergedIds ();
179145 array_push ($ mergedIds , $ mergedJob ->getId ());
@@ -185,35 +151,13 @@ public function merge(Job $mergedJob)
185151
186152 $ dataSize = $ this ->getDataSize ();
187153
188- // @todo Remove useless code on 3.16.0
189- if (isset ($ decodedData ['product_ids ' ])) {
190- $ decodedData ['product_ids ' ] = array_unique (array_merge (
191- $ decodedData ['product_ids ' ],
192- $ mergedJobDecodedData ['product_ids ' ]
193- ));
194-
195- $ dataSize = count ($ decodedData ['product_ids ' ]);
196- } elseif (isset ($ decodedData ['category_ids ' ])) {
197- $ decodedData ['category_ids ' ] = array_unique (array_merge (
198- $ decodedData ['category_ids ' ],
199- $ mergedJobDecodedData ['category_ids ' ]
200- ));
201-
202- $ dataSize = count ($ decodedData ['category_ids ' ]);
203- } elseif (isset ($ decodedData ['page_ids ' ])) {
204- $ decodedData ['page_ids ' ] = array_unique (array_merge (
205- $ decodedData ['page_ids ' ],
206- $ mergedJobDecodedData ['page_ids ' ]
207- ));
208-
209- $ dataSize = count ($ decodedData ['page_ids ' ]);
210- } elseif (isset ($ decodedData ['entity_ids ' ])) {
211- $ decodedData ['entity_ids ' ] = array_unique (array_merge (
212- $ decodedData ['entity_ids ' ],
213- $ mergedJobDecodedData ['entity_ids ' ]
154+ if (isset ($ decodedData ['entityIds ' ])) {
155+ $ decodedData ['entityIds ' ] = array_unique (array_merge (
156+ $ decodedData ['entityIds ' ],
157+ $ mergedJobDecodedData ['entityIds ' ]
214158 ));
215159
216- $ dataSize = count ($ decodedData ['entity_ids ' ]);
160+ $ dataSize = count ($ decodedData ['entityIds ' ]);
217161 }
218162
219163 $ this ->setDecodedData ($ decodedData );
@@ -225,7 +169,7 @@ public function merge(Job $mergedJob)
225169 /**
226170 * @return array
227171 */
228- public function getDefaultValues ()
172+ public function getDefaultValues (): array
229173 {
230174 $ values = [];
231175
@@ -235,7 +179,7 @@ public function getDefaultValues()
235179 /**
236180 * @return string
237181 */
238- public function getStatus ()
182+ public function getStatus (): string
239183 {
240184 $ status = JobInterface::STATUS_PROCESSING ;
241185
@@ -253,11 +197,11 @@ public function getStatus()
253197 /**
254198 * @param \Exception $e
255199 *
256- * @throws \Magento\Framework\Exception\ AlreadyExistsException
200+ * @throws AlreadyExistsException
257201 *
258202 * @return Job
259203 */
260- public function saveError (\Exception $ e )
204+ public function saveError (\Exception $ e ): Job
261205 {
262206 $ this ->setErrorLog ($ e ->getMessage ());
263207 $ this ->getResource ()->save ($ this );
0 commit comments