13
13
use Joomla \CMS \HTML \HTMLHelper ;
14
14
use Joomla \CMS \Language \Text ;
15
15
use Joomla \CMS \MVC \Model \ListModel ;
16
+ use Joomla \Database \DatabaseQuery ;
16
17
use PatchTester \GitHub \Exception \UnexpectedResponse ;
17
18
use PatchTester \Helper ;
19
+ use RuntimeException ;
18
20
19
21
// phpcs:disable PSR1.Files.SideEffects
20
22
\defined ('_JEXEC ' ) or die;
@@ -40,7 +42,7 @@ class PullsModel extends ListModel
40
42
* @var array
41
43
* @since 2.0
42
44
*/
43
- protected $ sortFields = array ( 'pulls.pull_id ' , 'pulls.title ' ) ;
45
+ protected $ sortFields = [ 'pulls.pull_id ' , 'pulls.title ' ] ;
44
46
/**
45
47
* Constructor.
46
48
*
@@ -86,7 +88,7 @@ public function getItems()
86
88
$ this ->getStart (),
87
89
$ this ->getState ()->get ('list.limit ' )
88
90
);
89
- $ db = $ this ->getDbo ();
91
+ $ db = $ this ->getDatabase ();
90
92
$ query = $ db ->getQuery (true )
91
93
->select ($ db ->quoteName (['name ' , 'color ' ]))
92
94
->from ($ db ->quoteName ('#__patchtester_pulls_labels ' ));
@@ -127,18 +129,18 @@ protected function getStoreId($id = '')
127
129
/**
128
130
* Gets an array of objects from the results of database query.
129
131
*
130
- * @param \JDatabaseQuery |string $query The query.
131
- * @param integer $limitstart Offset.
132
- * @param integer $limit The number of records.
132
+ * @param DatabaseQuery |string $query The query.
133
+ * @param integer $limitstart Offset.
134
+ * @param integer $limit The number of records.
133
135
*
134
136
* @return array An array of results.
135
137
*
136
138
* @since 2.0
137
139
* @throws RuntimeException
138
140
*/
139
- protected function getList ($ query , $ limitstart = 0 , $ limit = 0 )
141
+ protected function getList ($ query , int $ limitstart = 0 , int $ limit = 0 ): array
140
142
{
141
- return $ this ->getDbo ()->setQuery ($ query , $ limitstart , $ limit )
143
+ return $ this ->getDatabase ()->setQuery ($ query , $ limitstart , $ limit )
142
144
->loadObjectList ();
143
145
}
144
146
@@ -147,11 +149,11 @@ protected function getList($query, $limitstart = 0, $limit = 0)
147
149
*
148
150
* This method ensures that the query is constructed only once for a given state of the model.
149
151
*
150
- * @return \JDatabaseQuery A JDatabaseQuery object
152
+ * @return DatabaseQuery A DatabaseQuery object
151
153
*
152
154
* @since 2.0
153
155
*/
154
- protected function getListQueryCache ()
156
+ protected function getListQueryCache (): DatabaseQuery
155
157
{
156
158
// Capture the last store id used.
157
159
static $ lastStoreId ;
@@ -167,15 +169,15 @@ protected function getListQueryCache()
167
169
}
168
170
169
171
/**
170
- * Method to get a JDatabaseQuery object for retrieving the data set from a database.
172
+ * Method to get a DatabaseQuery object for retrieving the data set from a database.
171
173
*
172
- * @return \JDatabaseQuery A JDatabaseQuery object to retrieve the data set.
174
+ * @return DatabaseQuery A DatabaseQuery object to retrieve the data set.
173
175
*
174
176
* @since 2.0
175
177
*/
176
178
protected function getListQuery ()
177
179
{
178
- $ db = $ this ->getDbo ();
180
+ $ db = $ this ->getDatabase ();
179
181
$ query = $ db ->getQuery (true );
180
182
$ labelQuery = $ db ->getQuery (true );
181
183
$ query ->select ('pulls.* ' )
@@ -270,35 +272,36 @@ protected function getListQuery()
270
272
*
271
273
* @since 2.0
272
274
*/
273
- public function getSortFields ()
275
+ public function getSortFields (): array
274
276
{
275
277
return $ this ->sortFields ;
276
278
}
277
279
278
280
/**
279
281
* Method to request new data from GitHub
280
282
*
281
- * @param integer $page The page of the request
283
+ * @param int $page The page of the request
282
284
*
283
285
* @return array
284
286
*
287
+ * @throws RuntimeException
285
288
* @since 2.0
286
- * @throws \RuntimeException
287
289
*/
288
- public function requestFromGithub ($ page )
290
+ public function requestFromGithub (int $ page ): array
289
291
{
290
292
if ($ page === 1 ) {
291
- $ this ->getDbo ()->truncateTable ('#__patchtester_pulls ' );
292
- $ this ->getDbo ()->truncateTable ('#__patchtester_pulls_labels ' );
293
+ $ this ->getDatabase ()->truncateTable ('#__patchtester_pulls ' );
294
+ $ this ->getDatabase ()->truncateTable ('#__patchtester_pulls_labels ' );
293
295
}
294
296
295
297
try {
296
- // TODO - Option to configure the batch size
298
+ // TODO - Option to configure the batch size
297
299
$ batchSize = 100 ;
298
300
$ pullsResponse = Helper::initializeGithub ()->getOpenPulls ($ this ->getState ()->get ('github_user ' ), $ this ->getState ()->get ('github_repo ' ), $ page , $ batchSize );
299
301
$ pulls = json_decode ($ pullsResponse ->body );
300
302
} catch (UnexpectedResponse $ exception ) {
301
- throw new \RuntimeException (Text::sprintf ('COM_PATCHTESTER_ERROR_GITHUB_FETCH ' , $ exception ->getMessage ()), $ exception ->getCode (), $ exception );
303
+ throw new RuntimeException (
304
+ Text::sprintf ('COM_PATCHTESTER_ERROR_GITHUB_FETCH ' , $ exception ->getMessage ()), $ exception ->getCode (), $ exception );
302
305
}
303
306
304
307
// If this is page 1, let's check to see if we need to paginate
@@ -354,20 +357,20 @@ public function requestFromGithub($page)
354
357
355
358
$ labels [] = implode (', ' , [
356
359
(int ) $ pull ->number ,
357
- $ this ->getDbo ()->quote ($ label ->name ),
358
- $ this ->getDbo ()->quote ($ label ->color ),
360
+ $ this ->getDatabase ()->quote ($ label ->name ),
361
+ $ this ->getDatabase ()->quote ($ label ->color ),
359
362
]);
360
363
}
361
364
362
365
// Build the data object to store in the database
363
366
$ pullData = [
364
367
(int ) $ pull ->number ,
365
- $ this ->getDbo ()->quote (HTMLHelper::_ ('string.truncate ' , ($ pull ->title ?? '' ), 150 )),
366
- $ this ->getDbo ()->quote (HTMLHelper::_ ('string.truncate ' , ($ pull ->body ?? '' ), 100 )),
367
- $ this ->getDbo ()->quote ($ pull ->html_url ),
368
+ $ this ->getDatabase ()->quote (HTMLHelper::_ ('string.truncate ' , ($ pull ->title ?? '' ), 150 )),
369
+ $ this ->getDatabase ()->quote (HTMLHelper::_ ('string.truncate ' , ($ pull ->body ?? '' ), 100 )),
370
+ $ this ->getDatabase ()->quote ($ pull ->html_url ),
368
371
(int ) $ isRTC ,
369
372
(int ) $ isNPM ,
370
- $ this ->getDbo ()->quote ($ branch ),
373
+ $ this ->getDatabase ()->quote ($ branch ),
371
374
($ pull ->draft ? 1 : 0 )
372
375
];
373
376
$ data [] = implode (', ' , $ pullData );
@@ -379,25 +382,26 @@ public function requestFromGithub($page)
379
382
}
380
383
381
384
try {
382
- $ this ->getDbo ()->setQuery ($ this ->getDbo ()->getQuery (true )
385
+ $ this ->getDatabase ()->setQuery ($ this ->getDatabase ()->getQuery (true )
383
386
->insert ('#__patchtester_pulls ' )
384
387
->columns (['pull_id ' , 'title ' , 'description ' , 'pull_url ' ,
385
388
'is_rtc ' , 'is_npm ' , 'branch ' , 'is_draft ' ])
386
389
->values ($ data ));
387
- $ this ->getDbo ()->execute ();
388
- } catch (\RuntimeException $ exception ) {
389
- throw new \RuntimeException (Text::sprintf ('COM_PATCHTESTER_ERROR_INSERT_DATABASE ' , $ exception ->getMessage ()), $ exception ->getCode (), $ exception );
390
+ $ this ->getDatabase ()->execute ();
391
+ } catch (RuntimeException $ exception ) {
392
+ throw new RuntimeException (
393
+ Text::sprintf ('COM_PATCHTESTER_ERROR_INSERT_DATABASE ' , $ exception ->getMessage ()), $ exception ->getCode (), $ exception );
390
394
}
391
395
392
396
if ($ labels ) {
393
397
try {
394
- $ this ->getDbo ()->setQuery ($ this ->getDbo ()->getQuery (true )
398
+ $ this ->getDatabase ()->setQuery ($ this ->getDatabase ()->getQuery (true )
395
399
->insert ('#__patchtester_pulls_labels ' )
396
400
->columns (['pull_id ' , 'name ' , 'color ' ])
397
401
->values ($ labels ));
398
- $ this ->getDbo ()->execute ();
399
- } catch (\ RuntimeException $ exception ) {
400
- throw new \ RuntimeException (
402
+ $ this ->getDatabase ()->execute ();
403
+ } catch (RuntimeException $ exception ) {
404
+ throw new RuntimeException (
401
405
Text::sprintf (
402
406
'COM_PATCHTESTER_ERROR_INSERT_DATABASE ' ,
403
407
$ exception ->getMessage ()
@@ -424,6 +428,6 @@ public function requestFromGithub($page)
424
428
*/
425
429
public function truncateTable ()
426
430
{
427
- $ this ->getDbo ()->truncateTable ('#__patchtester_pulls ' );
431
+ $ this ->getDatabase ()->truncateTable ('#__patchtester_pulls ' );
428
432
}
429
433
}
0 commit comments