This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoverload.php
847 lines (725 loc) · 22 KB
/
overload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
<?php
/**
* @package overload
* @copyright (c) 2011-2020 Nicholas K. Dionysopoulos
* @license GNU General Public License version 3 or later
*/
use Faker\Provider\Biased;
use Joomla\CMS\Access\Access;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\LanguageFactoryInterface;
use Joomla\CMS\Menu\AbstractMenu;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Router\Router;
use Joomla\CMS\Table\Content as ContentTable;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\User\User;
// region Composer autoloader
/** @var \Composer\Autoload\ClassLoader $autoloader */
$autoloader = require_once(__DIR__ . '/vendor/autoload.php');
if (!is_object($autoloader))
{
die('Please run composer install in the Overload working directory before running this script.');
}
$autoloader->addPsr4('Overload\\', __DIR__ . '/Overload');
// endregion
// region Boilerplate
define('_JEXEC', 1);
define('JDEBUG', 0);
foreach ([__DIR__, getcwd()] as $curdir)
{
if (file_exists($curdir . '/defines.php'))
{
define('JPATH_BASE', realpath($curdir . '/..'));
require_once $curdir . '/defines.php';
break;
}
if (file_exists($curdir . '/../includes/defines.php'))
{
define('JPATH_BASE', realpath($curdir . '/..'));
require_once $curdir . '/../includes/defines.php';
break;
}
}
defined('JPATH_LIBRARIES') || die ('This script must be executed from the cli folder of your site.');
require_once __DIR__ . '/Overload/Cli/Application.php';
// endregion
ini_set('display_errors', 1);
error_reporting(E_ALL);
class OverloadCLI extends OverloadApplicationCLI
{
/**
* Faker's generator
*
* @var \Faker\Generator
* @since 2.0.0
*/
private $faker;
/**
* User IDs that can create categories.
*
* @var array
* @since 2.0.0
*/
private $categoryCreators;
/**
* User IDs that can create articles
*
* @var array
* @since 2.0.0
*/
private $articleCreators;
/**
* com_content's container
*
* @var \Joomla\DI\Container
*/
private $comContentContainer;
/**
* The main entry point of the application
*
* @return void
* @since 2.0.0
*/
public function doExecute(): void
{
// Show help if necessary
if ($this->input->getBool('help', false))
{
$this->showHelp();
}
// Read the configuration from the command line
$siteURL = $this->input->get('site-url', 'https://www.example.com');
$rootCategory = $this->input->getInt('root-catid', 0);
$catLevels = $this->input->getInt('categories-levels', 4);
$catCount = $this->input->getInt('categories-count', 3);
$catDelete = !$this->input->getBool('categories-nozap', false);
$catRandomize = $this->input->getBool('categories-randomize', false);
$articlesCount = $this->input->getInt('articles-count', 10);
$articlesDelete = !$this->input->getBool('articles-nozap', false);
$articlesRandomize = $this->input->getBool('articles-randomize', false);
// Initialize CLI routing
$this->initCliRouting($siteURL);
// Create the Faker object
$this->faker = Faker\Factory::create();
// Load languages
$jLang = Factory::getLanguage();
$jLang->load('com_content', JPATH_ADMINISTRATOR, null);
// Tell Joomla where to find models and tables
BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_categories/models');
BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_content/models');
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_categories/tables');
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_content/tables');
// Pretend that a Super User is logged in
$suIDs = $this->getSuperUsers();
$superUser = User::getInstance($suIDs[0]);
Factory::getSession()->set('user', $superUser);
// Joomla 4 still requires JPATH_COMPONENT :(
define('JPATH_COMPONENT', JPATH_ADMINISTRATOR . '/components/com_content');
if (empty($rootCategory))
{
if ($catCount == 0)
{
$this->out('You need to use --root-catid when setting --categories-count=0');
$this->close(1);
}
// Get the categories root
$rootCategory = $this->getCategoriesRoot();
}
else
{
// Verify the $rootCategory or fail early
$this->verifyCategory($rootCategory);
}
$this->out(sprintf("Articles and categories creation using category node %d as root.", $rootCategory));
if ($catDelete && ($catCount > 0))
{
$this->out("Deleting existing categories");
// Find existing categories under the root
$catIDs = $this->getAllChildrenCategoryIDs($rootCategory);
$this->out(sprintf(" Found %d categories to delete", count($catIDs)));
// For each category: delete its articles and delete the category itself
foreach ($catIDs as $catId)
{
$this->out(sprintf(" Deleting category %d", $catId));
$this->deleteCategory($catId);
}
}
$catIDs = [$rootCategory];
// Create categories, $catLevels levels deep. Store IDs in $catIDs.
if ($catCount > 0)
{
$this->out('Creating categories');
$catIDs = [];
$previousLevelIDs = [$rootCategory];
$this->categoryCreators = $this->getGroupCreators();
for ($i = 0; $i < $catLevels; $i++)
{
$this->out(sprintf(' Creating categories %d level(s) from the root', $i + 1));
$thisLevelIDs = [];
$createCatCount = $catCount;
foreach ($previousLevelIDs as $parentId)
{
if ($catRandomize)
{
$createCatCount = $this->faker->biasedNumberBetween(1, $catCount, [
Biased::class, 'linearHigh',
]);
}
$this->out(sprintf(' %d categories under root ID %d', $createCatCount, $parentId));
for ($j = 0; $j < $createCatCount; $j++)
{
$thisLevelIDs[] = $this->createCategory($parentId);
}
}
$catIDs = array_merge($catIDs, $thisLevelIDs);
$previousLevelIDs = $thisLevelIDs;
}
}
$this->out(sprintf('We have a total of %d categories to create articles in.', count($catIDs)));
foreach ($catIDs as $catId)
{
// Find out which users can create articles in this category
$this->articleCreators = $this->getCategoryAuthors($catId);
// Delete articles unless $articlesDelete is false
if ($articlesDelete)
{
$this->out(sprintf(' Deleting old articles from category %d', $catId));
$this->deleteArticlesInCategory($catId);
}
// Create articles
$createArticleCount = $articlesCount;
if ($articlesRandomize)
{
$createArticleCount = $this->faker->biasedNumberBetween(1, $articlesCount, [
Biased::class, 'linearHigh',
]);
}
$this->out(sprintf(' Creating %d articles for category %d', $createArticleCount, $catId));
for ($j = 0; $j < $createArticleCount; $j++)
{
$this->createArticle($catId);
}
}
}
/**
* Returns the site Router object.
*
* @param string|null $name The name of the application.
* @param array $options An optional associative array of configuration settings.
*
* @return Router|null A JRouter object
* @since 2.0.0
*/
public function getRouter($name = null, array $options = []): ?Router
{
try
{
return Router::getInstance('site', $options);
}
catch (Exception $e)
{
return null;
}
}
/**
* Returns a Joomla menu object.
*
* @param string|null $name
* @param array $options
*
* @return AbstractMenu|null
* @throws Exception
* @since 2.0.0
*/
public function getMenu($name = null, $options = []): ?AbstractMenu
{
return AbstractMenu::getInstance($name, $options);
}
public function isClient($client)
{
return $client === 'administrator';
}
public function getClientId(): int
{
return 1;
}
/**
* Initializes the site routing under CLI
*
* @param string $siteURL The URL to the site
*
* @throws ReflectionException
* @since 2.0.0
*/
private function initCliRouting(string $siteURL = 'https://www.example.com')
{
// Set up the base site URL in JUri
$uri = Uri::getInstance($siteURL);
$_SERVER['HTTP_HOST'] = $uri->toString(['host', 'port']);
$_SERVER['REQUEST_URI'] = $uri->getPath();
$refClass = new ReflectionClass(Uri::class);
$refInstances = $refClass->getProperty('instances');
$refInstances->setAccessible(true);
$instances = $refInstances->getValue();
$instances['SERVER'] = $uri;
$refInstances->setValue($instances);
$base = [
'prefix' => $uri->toString(['scheme', 'host', 'port']),
'path' => rtrim($uri->toString(['path']), '/\\'),
];
$refBase = $refClass->getProperty('base');
$refBase->setAccessible(true);
$refBase->setValue($base);
/**
* Set up the SEF mode in the router.
*
* Only applicable on Joomla 3. The site router in Joomla 4 sets itself up automatically.
*/
if (version_compare(JVERSION, '3.999.999', 'le'))
{
$this->getRouter()->setMode($this->get('sef', 0));
}
}
/**
* Show the help text
*
* @since 2.0.0
*/
private function showHelp(): void
{
echo file_get_contents(__DIR__ . '/help.txt');
$this->close();
}
/**
* Create a category and return its ID or NULL if creation failed
*
* @param int $parent_id Parent category ID
*
* @return int|null Created category ID or NULL if creation failed
*
* @throws Exception
* @since 2.0.0
*/
private function createCategory(int $parent_id = 1): ?int
{
$title = $this->faker->sentence(8);
$alias = ApplicationHelper::stringURLSafe($title);
$uid = $this->faker->randomElement($this->categoryCreators);
if (version_compare(JVERSION, '3.999.999', 'le'))
{
/** @var CategoriesModelCategory $model */
$model = BaseDatabaseModel::getInstance('Category', 'CategoriesModel');
}
else
{
/** @var MVCFactoryInterface $factory */
$factory = $this->bootComponent('com_categories')->getMVCFactory();
/** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $model */
$model = $factory->createModel('Category', 'Administrator');
}
$parent = $model->getItem($parent_id);
$data = [
'parent_id' => $parent_id,
'level' => $parent->level + 1,
'extension' => 'com_content',
'title' => $title,
'alias' => $alias,
'description' => $this->getRandomParagraphs(3, true),
'access' => 1,
'params' => ['target' => '', 'image' => ''],
'metadata' => ['page_title' => '', 'author' => '', 'robots' => '', 'tags' => ''],
'hits' => 0,
'language' => '*',
'associations' => [],
'published' => 1,
'created_user_id' => $uid,
];
// Save the category
$result = $model->save($data);
// If the save succeeded return the numeric category ID
if ($result !== false)
{
return $model->getState($model->getName() . '.id');
}
// Let's try to load a category of the same alias
$db = Factory::getDbo();
$query =
$db->getQuery(true)
->select('id')
->from($db->qn('#__categories'))
->where($db->qn('alias') . ' = ' . $db->q($alias));
$db->setQuery($query);
$id = $db->loadResult() ?? 0;
// Nope. No dice. Return null.
if (!$id)
{
return null;
}
// Enable an existing category
$cat = $model->getItem($id);
if (!$cat->published)
{
$cat->published = 1;
}
$cat = (array) $cat;
$model->save($cat);
return $id;
}
/**
* Creates an article in the specified category
*
* @param int $cat_id The category to create the article in
*
* @return void
* @since 2.0.0
*/
private function createArticle($cat_id = 1): void
{
$title = $this->faker->sentence(8);
$alias = ApplicationHelper::stringURLSafe($title);
$data = [
'title' => $title,
'alias' => $alias,
'introtext' => $this->getRandomParagraphs(1, false),
'fulltext' => $this->getRandomParagraphs(6, true),
'state' => 1,
'sectionid' => 0,
'mask' => 0,
'catid' => $cat_id,
'created_by' => $this->faker->randomElement($this->articleCreators),
'created' => (new Date($this->faker->dateTimeBetween('-5 years', 'now')->getTimestamp()))->toSql(),
'created_by_alias' => $this->faker->name,
'attribs' => [
"show_title" => "",
"link_titles" => "",
"show_intro" => "",
"show_category" => "",
"link_category" => "",
"show_parent_category" => "",
"link_parent_category" => "",
"show_author" => "",
"link_author" => "",
"show_create_date" => "",
"show_modify_date" => "",
"show_publish_date" => "",
"show_item_navigation" => "",
"show_icons" => "",
"show_print_icon" => "",
"show_email_icon" => "",
"show_vote" => "",
"show_hits" => "",
"show_noauth" => "",
"alternative_readmore" => "",
"article_layout" => "",
],
'version' => 1,
'parentid' => 0,
'ordering' => 0,
'metakey' => '',
'metadesc' => '',
'access' => 1,
'hits' => 0,
'featured' => 0,
'language' => '*',
'associations' => [],
'metadata' => '{"tags":[]}',
];
if (version_compare(JVERSION, '3.999.999', 'le'))
{
$data['id'] = 0;
/** @var ContentModelArticle $model */
$model = BaseDatabaseModel::getInstance('Article', 'ContentModel');
}
else
{
/** @var MVCFactoryInterface $factory */
$factory = $this->bootComponent('com_content')->getMVCFactory();
/** @var Joomla\Component\Content\Administrator\Model\ArticleModel $model */
$model = $factory->createModel('Article', 'Administrator');
}
$result = $model->save($data);
if (!$result)
{
throw new RuntimeException($model->getError());
}
}
/**
* Get a number of random paragraphs of HTML text
*
* @param int $howMany How many paragraphs do you want
* @param bool $randomCount Should I randomize the number of paragraphs, max $howMany?
*
* @return string The HTML string of your random paragraphs
* @since 2.0.0
*/
private function getRandomParagraphs(int $howMany, bool $randomCount = true): string
{
if ($randomCount)
{
$howMany = $this->faker->numberBetween(1, $howMany);
}
return implode(',', array_map(function ($p) {
return "<p>" . $p . "</p>";
}, $this->faker->paragraphs($howMany, false)));
}
/**
* Get the ID of the root of all categories.
*
* @return int
*
* @since 2.0.0
*/
private function getCategoriesRoot(): int
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('id'))
->from($db->qn('#__categories'))
->where($db->qn('parent_id') . ' = ' . $db->q(0))
->where($db->qn('level') . ' = ' . $db->q(0));
return $db->setQuery($query)->loadResult() ?? 0;
}
/**
* Verify a category exists and belongs to com_content
*
* @param int $catID The category ID to check
*
* @return void
* @since 2.0.0
*/
private function verifyCategory(int $catID): void
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('id'))
->from($db->qn('#__categories'))
->where($db->qn('extension') . ' = ' . $db->q('com_content'))
->where($db->qn('parent_id') . ' > ' . $db->q(0))
->where($db->qn('level') . ' > ' . $db->q(0))
->where($db->qn('id') . ' = ' . $db->q($catID));
if ($db->setQuery($query)->loadResult() != $catID)
{
throw new RuntimeException(sprintf('Category ID %d was not found or does not belong to Joomla articles (com_content).', $catID));
}
}
/**
* Get all the content categories that are children (infinite levels deep) of the root category.
*
* @param int $catID Root category ID
*
* @return array Children category IDs, ordered from leaf nodes down (leaves first, immediate root children last)
*
* @since 2.0.0
*/
private function getAllChildrenCategoryIDs(int $catID): array
{
$db = Factory::getDbo();
// First, I need the lft and rgt of my root category
$query = $db->getQuery(true)
->select([
$db->qn('lft'),
$db->qn('rgt'),
])
->from($db->qn('#__categories'))
->where($db->qn('id') . ' = ' . $db->q($catID));
$rootInfo = $db->setQuery($query)->loadAssoc();
if (empty($rootInfo))
{
throw new RuntimeException(sprintf("Could not retrieve information for category %d", $catID));
}
/**
* Now, I can find the IDs of the subtree nodes.
*
* Make sure to filter for extension because the root node contains everything, not just com_content.
*
* Categories are returned in descending level order. This way the category nuking will go from the leaf nodes
* towards the root nodes. It wouldn't work the other way around since we'd be trying to delete a non-empty
* category.
*/
$query = $db->getQuery(true)
->select($db->qn('id'))
->from($db->qn('#__categories'))
->where($db->qn('extension') . ' = ' . $db->q('com_content'))
->where($db->qn('lft') . ' > ' . $db->q($rootInfo['lft']))
->where($db->qn('rgt') . ' < ' . $db->q($rootInfo['rgt']))
->order($db->qn('level') . ' DESC');
return $db->setQuery($query)->loadColumn() ?? [];
}
/**
* Deletes a category and all of its articles
*
* @param int $catID THe category to delete
*
* @return void
* @since 2.0.0
*/
private function deleteCategory(int $catID): void
{
// Delete all of the category articles.
$this->deleteArticlesInCategory($catID);
$pks = [$catID];
if (version_compare(JVERSION, '3.999.999', 'le'))
{
// Delete the category itself.
/** @var CategoriesTableCategory $table */
$table = Table::getInstance('Category', 'CategoriesTable');
/** @var CategoriesModelCategory $model */
$model = BaseDatabaseModel::getInstance('Category', 'CategoriesModel');
// Joomla requires me to trash before deleting
$table->publish($pks, -2);
if (!$model->delete($pks))
{
throw new RuntimeException($model->getError());
}
}
/** @var MVCFactoryInterface $factory */
$factory = $this->bootComponent('com_categories')->getMVCFactory();
/** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $model */
$model = $factory->createModel('Category', 'Administrator');
$model->publish($pks, -2);
if (!$model->delete($pks))
{
throw new RuntimeException($model->getError());
}
}
/**
* Delete all articles in a category
*
* @param int $catID The category ID the articles of which are going to be deleted
*
* @return void
* @since 2.0.0
*/
private function deleteArticlesInCategory(int $catID): void
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('id'))
->from($db->qn('#__content'))
->where($db->qn('catid') . ' = ' . $db->q($catID));
$articleIDs = $db->setQuery($query)->loadColumn() ?? [];
if (empty($articleIDs))
{
return;
}
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('id'))
->from($db->qn('#__content'))
->where($db->qn('catid') . ' = ' . $db->q($catID))
->where($db->qn('state') . ' != -2');
$untrashedIDs = $db->setQuery($query)->loadColumn() ?? [];
// Joomla 3
if (version_compare(JVERSION, '3.999.999', 'le'))
{
/** @var ContentModelArticle $model */
$model = BaseDatabaseModel::getInstance('Article', 'ContentModel');
/** @var ContentTable $table */
$table = ContentTable::getInstance('Content');
// We must trash the articles before deleting them because that's the One True Joomla! Way
$table->publish($untrashedIDs, -2);
if (!$model->delete($articleIDs))
{
throw new RuntimeException($model->getError());
}
return;
}
/** @var MVCFactoryInterface $factory */
$factory = $this->bootComponent('com_content')->getMVCFactory();
/** @var Joomla\Component\Content\Administrator\Model\ArticleModel $model */
$model = $factory->createModel('Article', 'Administrator');
if (!$model->publish($untrashedIDs, -2))
{
throw new RuntimeException($model->getError());
}
if (!$model->delete($articleIDs))
{
throw new RuntimeException($model->getError());
}
}
/**
* Return all user group IDs known to Joomla
*
* @return array
*
* @since 2.0.0
*/
private function getAllUserGroups(): array
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('id'))
->from($db->qn('#__usergroups'));
return $db->setQuery($query)->loadColumn() ?? [];
}
/**
* Returns the user IDs which can create groups
*
* @return array
*
* @since 2.0.0
*/
private function getGroupCreators(): array
{
$authorGroups = array_filter($this->getAllUserGroups(), function ($gid) {
return Access::checkGroup($gid, 'core.create') ||
Access::checkGroup($gid, 'core.admin') ||
Access::checkGroup($gid, 'core.create', 'com_categories');
});
$users = [];
foreach ($authorGroups as $gid)
{
$users = array_merge($users, Access::getUsersByGroup($gid));
}
return $users;
}
/**
* Returns the user IDs of Super Users
*
* @return array
*
* @since 2.0.0
*/
private function getSuperUsers(): array
{
$authorGroups = array_filter($this->getAllUserGroups(), function ($gid) {
return Access::checkGroup($gid, 'core.admin');
});
$users = [];
foreach ($authorGroups as $gid)
{
$users = array_merge($users, Access::getUsersByGroup($gid));
}
return $users;
}
/**
* Returns all the users who have core.create privileges for the given category.
*
* @param int $catId
*
* @return array
*
* @since 2.0.0
*/
private function getCategoryAuthors(int $catId): array
{
Access::preload('com_content.category.' . $catId);
$authorGroups = array_filter($this->getAllUserGroups(), function ($gid) use ($catId) {
return Access::checkGroup($gid, 'core.create') ||
Access::checkGroup($gid, 'core.admin') ||
Access::checkGroup($gid, 'core.create', 'com_content.category.' . $catId);
});
$users = [];
foreach ($authorGroups as $gid)
{
$users = array_merge($users, Access::getUsersByGroup($gid));
}
return $users;
}
}
OverloadApplicationCLI::getInstance('OverloadCLI')->execute();