-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgdo_adm.php
More file actions
1314 lines (1186 loc) · 34.7 KB
/
gdo_adm.php
File metadata and controls
1314 lines (1186 loc) · 34.7 KB
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
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
use GDO\Admin\Method\Install;
use GDO\CLI\CLI;
use GDO\CLI\REPL;
use GDO\Core\Application;
use GDO\Core\Debug;
use GDO\Core\GDO_Module;
use GDO\Core\GDO_ModuleVar;
use GDO\Core\GDT;
use GDO\Core\GDT_Hook;
use GDO\Core\GDT_Method;
use GDO\Core\Logger;
use GDO\Core\Method\ClearCache;
use GDO\Core\ModuleLoader;
use GDO\Core\ModuleProviders;
use GDO\Core\Website;
use GDO\Crypto\BCrypt;
use GDO\DB\Cache;
use GDO\DB\Database;
use GDO\Form\GDT_Form;
use GDO\Install\Config;
use GDO\Install\GDT_DocsFile;
use GDO\Install\Installer;
use GDO\Install\Method\Configure;
use GDO\Install\Method\InstallCronjob;
use GDO\Install\Method\Security;
use GDO\Install\Method\SystemTest;
use GDO\Install\Method\Webserver;
use GDO\Install\Module_Install;
use GDO\Language\Trans;
use GDO\UI\GDT_Error;
use GDO\UI\GDT_Page;
use GDO\UI\GDT_Success;
use GDO\User\GDO_Permission;
use GDO\User\GDO_User;
use GDO\User\GDO_UserPermission;
use GDO\User\GDT_UserType;
use GDO\Util\FileUtil;
use GDO\Util\PP;
use GDO\Util\Strings;
/**
* The gdo_adm.php CLI application manages administrative tasks.
* It shall not be accesible to normal users!
*
* @version 7.0.3
* @since 6.10.0
*
* @example ./gdo_adm.sh systemtest
* @example ./gdo_adm.sh configure
* @example ./gdo_adm.sh provide helpdesk
* @example ./gdo_adm.sh install --all
* @example ./gdo_adm.sh secure
* @example ./gdo_adm.sh config --reset perf sidebar
* @example ./gdo_adm.sh config core guests 0
* @example ./gdo_adm.sh update
* @example ./gdo_adm.sh --force migrate gdo_user
* @example ./gdo_adm.sh --force migrate user
* @example ./gdo_adm.sh migrate --all
* @example ./gdo_adm.sh exec backup.create
*
* @author gizmore
*
* @see gdo_adm.sh
* @see gdo_fix.sh - To fix an installation.
* @see gdo_update.sh - To update your installation.
* @see gdo_reset.sh - To reset your installation code to factory defaults. Own files are not deleted. Configs are unchanged.
* @see gdo_test.sh - For unit testing
* @see gdo_yarn.sh - To install javascript dependencies
* @see gdo_post_install.sh - To finish the installation process
* @see gdo_cronjob.sh - To run the module cronjobs
* @see bin/gdo - To invoke a method via the CLI - for normal users.
*/
/** @var int $argc * */
/**
* Show usage of the gdoadm.sh shell command, or the usage of a single command.
*
* @example gdoadm.sh modules
* @example gdoadm.sh provide TBS
* @example ./bin/gdo mail.send giz,Hi-title-there,, wanker!,This is the mail body. Parameters are separated via comma. Escape comma with double comma.
*/
function printUsage(int $code = -1, string $cmd = null): void
{
global $app, $exe;
$commands = [
'DIV-Spawn',
'docs' => "$exe -iv %CMD% - To print and run install instructions from the DOCS at https://github.com/gizmore/phpgdo",
'systemtest' => "$exe %CMD% [<config.php>] - To run the gdo core systemtest.",
'configure' => "$exe -iF %CMD% [<config.php>] - To generate a `protected/config.php.`.",
'test' => "$exe %CMD% [<config.php>] - To test a `protected/config.php.`.",
'admin' => "$exe -d %CMD% <username> [<password>] - To (re)-set or delete an admin.",
'cronjob' => "$exe %CMD% - To print cronjob instructions.",
'webconf' => "$exe %CMD% - To print webserver configuration examples.",
'secure' => "$exe %CMD% - To secure your installation after an install.",
'DIV-Modules',
'modules' => "$exe -a %CMD% [<module>] - To show a list of modules or show module details.",
'provide' => "$exe -a %CMD% [<module>] - To download all modules that are required to provide a module,",
'install' => "$exe -ac %CMD% [<module>] - To install a module and it's dependencies,",
'wipe' => "$exe -a %CMD% [<module>] - To uninstall modules,",
'DIV-Updates',
'cc' => "$exe %CMD% - To clear all caches. Convinient for developing.",
'update' => "$exe %CMD% - To run post processing CI steps after `gdo_update.sh`.",
'confgrade' => "$exe %CMD% - Upgrade your config.php with new config vars.",
'vendor' => "$exe -af %CMD% [<module>] - Clear, needs force, and reinstall, third party libraries.",
'migrate' => "$exe -afv %CMD% [<module>] - To migrate gdo db tables for an installed module. Handle with care.!",
'pp' => "$exe %CMD% - To run the PP php-preprocessor on all files.",
'DIV-Config',
'config' => "$exe -ar %CMD% [<module>] - To show or reset all config variables for modules,",
'config ' => "$exe -r %CMD% <module> <key> - To show or reset a single module config variable,",
'config ' => "$exe %CMD% <module> <key> <var> - To set the value of a config variable.",
'configtest' => "$exe -af %CMD% [<module>] - To validate the config for modules.",
];
if ($app->verbose)
{
echo "Tip: you can have a 'cli-only' `protected/config_cli.php`.\n";
echo "Note: PHP getopts syntax is used here.\n";
echo "\n";
echo "Toggles:\n";
echo "-a == --all - To select all available modules.\n";
echo "-c == --configured - To select all installed modules.\n";
echo "-d == --delete - To delete admins.\n";
echo "-f == --fix - To fix entries in module configurations and settings.\n";
echo "-F == --force - To force auto detection and recreation of a protected/config.php.\n";
echo "-r == --reset - To reset config vars.\n";
echo "-s == --ssh - To clone via ssh protocol, only for the developers.\n";
echo "-v == --verbose - For more output.\n";
echo "-3 == --libraries - To select third party libraries.\n";
echo "\n";
}
if ($cmd)
{
foreach ($commands as $c => $usage)
{
if (str_starts_with((string)$c, $cmd))
{
$usage = is_numeric($c) ? $usage : str_replace('%CMD%', $c, $usage);
print("Usage: {$usage}\n");
}
}
}
else
{
foreach ($commands as $c => $usage)
{
$usage = is_numeric($c) ? $usage : str_replace('%CMD%', $c, $usage);
print("Usage: {$usage}\n");
}
}
die($code);
}
chdir(__DIR__);
require 'GDO7.php';
# forced?
if (FileUtil::isFile('protected/config_cli.php'))
{
require 'protected/config_cli.php';
}
elseif (FileUtil::isFile('protected/config.php'))
{
require 'protected/config.php';
}
$app = new class extends Application
{
public function __construct()
{
parent::__construct();
self::$INSTANCE = $this;
}
public function isInstall(): bool
{
return true;
}
###############
### Options ###
###############
public bool $all = false;
public function all(bool $all = true): self
{
$this->all = $all;
return $this;
}
public bool $configured = false;
public function configured(bool $configured = true): self
{
$this->configured = $configured;
return $this;
}
public bool $delete = false;
public function delete(bool $delete = true): self
{
$this->delete = $delete;
return $this;
}
public bool $fix = false;
public function fix(bool $fix = true): self
{
$this->fix = $fix;
return $this;
}
public bool $force = false;
public function force(bool $force = true): self
{
$this->force = $force;
return $this;
}
public bool $interactive = false;
public function interactive(bool $interactive = true): self
{
$this->interactive = $interactive;
return $this;
}
public bool $postInstall = false;
public function postInstall(bool $postInstall = true): self
{
$this->postInstall = $postInstall;
return $this;
}
public bool $quiet = false;
public function quiet(bool $quiet = true): self
{
$this->quiet = $quiet;
return $this;
}
public bool $reset = false;
public function resetting(bool $r = true): self
{
$this->reset = $r;
return $this;
}
public bool $ssh = false;
public function ssh(bool $ssh = true): self
{
$this->ssh = $ssh;
return $this;
}
public bool $verbose = false;
public function verbose(bool $verbose = true): self
{
$this->verbose = $verbose;
return $this;
}
public bool $vendor = false;
public function vendor(bool $vendor = true): self
{
$this->vendor = $vendor;
return $this;
}
};
$app->modeDetected(GDT::RENDER_CLI)->cli()->verb(GDT_Form::POST);
# Load config defaults
if (!defined('GDO_CONFIGURED'))
{
define('GDO_DB_ENABLED', false);
define('GDO_WEB_ROOT', '/');
Config::configure(); # autoconfig
}
// new ModuleLoader(GDO_PATH . 'GDO/');
CLI::setServerVars();
Logger::init('gdo_adm', GDO_ERROR_LEVEL); # init without username
Database::init(GDO_DB_NAME);
Cache::flush();
Trans::$ISO = GDO_LANGUAGE;
Debug::init(false, false);
$loader = ModuleLoader::instance();
define('GDO_CORE_STABLE', true);
if ($argc === 1)
{
printUsage(0);
}
$exe = array_shift($argv);
$argc = count($argv);
$i = 0;
$o = getopt('acdfFhipqrsv3', ['all', 'configured', 'delete', 'fix', 'force', 'help', 'interactive', 'post-install', 'quiet', 'reset', 'ssh', 'verbose', 'vendor'], $i);
if (isset($o['a']) || isset($o['all']))
{
$app->all();
}
if (isset($o['c']) || isset($o['configured']))
{
$app->configured();
}
if (isset($o['d']) || isset($o['delete']))
{
$app->delete();
}
if (isset($o['f']) || isset($o['fix']))
{
$app->fix();
}
if (isset($o['F']) || isset($o['force']))
{
$app->force();
}
if (isset($o['h']) || isset($o['help']))
{
printUsage(0);
}
if (isset($o['i']) || isset($o['interactive']))
{
$app->interactive();
}
if (isset($o['p']) || isset($o['post-install']))
{
$app->postInstall();
}
if (isset($o['q']) || isset($o['quiet']))
{
$app->quiet();
}
if (isset($o['r']) || isset($o['reset']))
{
$app->resetting();
}
if (isset($o['s']) || isset($o['ssh']))
{
$app->ssh();
}
if (isset($o['v']) || isset($o['verbose']))
{
$app->verbose();
}
if (isset($o['3']) || isset($o['libraries']))
{
$app->vendor();
}
array_unshift($argv, $exe);
$argv = array_slice($argv, $i);
array_unshift($argv, $exe);
$cmd = $argv[1] ?? null;
$argc = count($argv);
if (isset($o['h']) || isset($o['help']))
{
printUsage(0, $cmd);
}
# Fix argc/argv
$command = $cmd;
//$argc = count($argv);
$db = (bool)GDO_DB_ENABLED;
switch ($command)
{
case 'install':
Database::init();
# fallthrough
case 'configure':
case 'systemtest':
case 'wipe':
case 'provide':
case 'revendor':
$db = false;
break;
default:
if ($db)
{
Database::init();
}
break;
}
$modules = [];
if (!$db)
{
$core = $loader->loadModuleFS('Core');
$core->onLoadLanguage();
$inst = $loader->loadModuleFS('Install');
$inst->onLoadLanguage();
}
$loader->loadModules($db, true);
//if ($db && ($command !== 'install'))
//{
// $loader->initModuleVars();
//}
$loader->initModules($db);
# Run!
if ($command === 'cc')
{
ClearCache::make()->execute();
echo "Caches cleared!\n";
}
elseif ($command === 'docs')
{
echo "Welcome to the GDOv7 interactive installer.\n";
$gdt = GDT_DocsFile::make('file');
$now = 'first';
while (REPL::confirm('Do you want, here, to print a few lines of the phpgdo DOCS of https://github.com/gizmore/phpgdo?', false))
{
while (!$gdt->hasError())
{
$gdt->reset();
if (REPL::changedGDTVar($gdt, "Which File $now? "))
{
echo file_get_contents($gdt->getDocsPath());
echo "\n";
$now = 'now';
}
else
{
break 2;
}
}
}
REPL::confirmOrDie("The biggest requirements are mysql|postgres|sqlite, git[4window] and PHP>=8.2, OK?", false);
if (REPL::confirm('You can check the requirements with `./gdo_adm.sh systemtest`.', false))
{
system('php gdo_adm.php systemtest');
REPL::confirmOrDie("Was the system test OK?");
}
echo "You need a file named `protected/config.php`.\n";
if (REPL::confirm('Shall i run `php gdo_adm.php configure` for you?', true))
{
system('php gdo_adm.php -i configure');
}
REPL::abortable('Next we will run `php gdo_adm.php test`, Ok? ');
if ($code = system('php gdo_adm.php test'))
{
die("`php gdo_adm.php test` failed with exit code $code");
}
echo "Good, you can connect to your database.\n";
if (REPL::confirm('Do you want to install the core now? ', true))
{
echo "Ok, running `php gdo_adm.php install core` in a second...\n";
sleep(1);
echo "Hehe\n";
if ($code = system('php gdo_adm.php install core --post-install'))
{
die("`php gdo_adm.php install core` failed with exit code $code");
}
}
$folder = GDO_PATH . 'bin/';
echo "You now can add $folder to your PATH environment variable.\n";
if (REPL::acknowledge('Do you want to see instructions?'))
{
echo "TODO\n";
}
echo "See you around!\n";
}
elseif ($command === 'systemtest')
{
if ($argc !== 2)
{
printUsage(1);
}
echo SystemTest::make()->execute()->renderCLI();
}
elseif ($command === 'configure')
{
if ($argc === 2)
{
$argc++;
$argv[2] = 'config.php'; # default config filename
}
$inputs = [
'filename' => $argv[2],
'save_config' => '1',
];
if ($app->interactive)
{
$n = 0;
$fields = Config::fields();
$count = count($fields);
while ($n < $count)
{
$gdt = $fields[$n];
$gdt->reset(true);
if (!$gdt->isWriteable())
{
$n++;
}
else
{
REPL::changeGDT($gdt);
if (!$gdt->hasError())
{
$n++;
}
}
}
}
$response = Configure::make()->executeWithInputs($inputs, false);
echo $response->render();
if (Application::isSuccess())
{
Security::make()->protectFolders();
echo "You should now edit this file by hand.\n";
echo "Afterwards execute {$argv[0]} test config.\n";
}
}
elseif ($command === 'test')
{
echo Configure::make()->onTestConfig()->renderCLI();
echo "---\n\n\n";
echo "Your configuration seems solid.\n";
echo "You can now try to php {$argv[0]} install <module>.\n";
echo "A list of official modules is shown via php {$argv[0]} modules.\n";
echo "Before you can install a module, you have to clone it.\n";
echo "Example: cd GDO; git clone --recursive https://github.com/gizmore/gdo6-session-cookie Session; cd ..\n";
echo 'Please note that some modules have multiple providesrs.';
echo "E.g, for the session module, you can choose between phpgdo-session-db and phpgdo-session-cookie.\n";
echo "Any Session provider has just to be cloned as a folder named GDO/Session/, voila.\n";
}
elseif ($command === 'modules')
{
$modules = [];
if ($app->all)
{
$modules = $loader->getModules();
}
elseif ($argc == 3)
{
$module = $loader->loadModuleFS($argv[2]);
if (!$module)
{
echo "Module {$argv[2]} not found.\n";
}
else
{
$modules = [$module];
}
}
else
{
printUsage(-409, $command);
}
foreach ($modules as $module)
{
printf("%16s (%s): %s\n", $module->getName(), $module->license, Strings::substrTo(Installer::getModuleDescription($module, true), "\n"));
if (count($modules) === 1)
{
printf("Dependencies: %s\n", implode(', ', $module->getDependencies()));
printf("Friendencies: %s\n", implode(', ', $module->getFriendencies()));
}
}
}
elseif ($command === 'install')
{
// if (!$db)
// {
// echo \GDO\UI\TextStyle::bold("You do not have GDO_DB_ENABLED. I cannot install anything.\n", true, 'red');
// die(-1);
// }
$deps = [];
$mode = $app->all ? 2 : 1;
$git = ModuleProviders::GIT_PROVIDER;
if ($mode === 1)
{
if ($argc !== 3)
{
printUsage(409, $command);
}
$deps[] = 'Core';
$moduleNames = explode(',', $argv[2]);
foreach ($moduleNames as $moduleName)
{
$module = ModuleLoader::instance()->loadModuleFS($moduleName);
$deps[] = $module->getName();
if (!$module)
{
echo "Unknown module. Try {$argv[0]} modules.\n";
die(1);
}
$deps = array_merge($deps, $module->getDependencies());
}
$deps = array_unique($deps);
}
elseif ($mode === 2)
{
if ($argc !== 2)
{
printUsage(409, $command);
}
$modules = ModuleLoader::instance()->loadModules(true, true, true);
$modules = array_filter($modules, function (GDO_Module $module)
{
return $module->isInstallable();
});
$deps = array_map(function (GDO_Module $mod)
{
return $mod->getName();
}, $modules);
$cnt = count($deps);
echo "Installing all {$cnt} modules.\n";
}
$deps[] = 'Core';
$deps = array_unique($deps);
$cnt = 0;
$allResolved = true; # All required modules provided?
while ($cnt !== count($deps))
{
$cnt = count($deps);
foreach ($deps as $dep)
{
$depmod = ModuleLoader::instance()->getModule($dep, true);
if (!$depmod)
{
if ($allResolved === true)
{
echo "Missing dependencie(s)!\n";
echo "Please note that this list may not be complete, because missing modules might have more dependencies.\n";
}
$allResolved = false;
$providers = @ModuleProviders::$PROVIDERS[$dep];
if (!$providers)
{
echo "{$dep}: Not an official module or a typo somewhere. No Provider known.\n";
}
elseif (is_array($providers))
{
echo "{$dep}: Choose between multiple possible providers.\n";
foreach ($providers as $provider)
{
printf("%20s: cd GDO; git clone --recursive {$git}{$provider} {$dep}; cd ..\n", $dep);
}
}
else
{
printf("%20s: cd GDO; git clone --recursive {$git}{$providers} {$dep}; cd ..\n", $dep);
}
continue;
}
$deps = array_unique(array_merge($depmod->getDependencies(), $deps));
}
}
$deps = array_unique($deps);
if (!$allResolved)
{
echo "Some required modules are not provided by your current GDO/ folder.\n";
echo "Please clone the modules like stated above.\n";
echo "Repeat the process until all dependencies are resolved.\n";
die(2);
}
$deps2 = [];
foreach ($deps as $moduleName)
{
$mod = ModuleLoader::instance()->getModule($moduleName);
$deps2[$moduleName] = $mod->priority;
}
sort($deps);
asort($deps2);
echo t('msg_installing_modules', [
implode(', ', $deps),
]) . "\n";
$modules = array_map(function (string $moduleName)
{
return ModuleLoader::instance()->getModule($moduleName);
}, array_keys($deps2));
Installer::installModules($modules);
if ($app->postInstall)
{
system('bash gdo_post_install.sh --quiet');
}
echo "Done.\n";
}
elseif ($command === 'admin')
{
if ($argc !== 4)
{
printUsage(409, $command);
}
if (!($user = GDO_User::getByName($argv[2])))
{
$user = GDO_User::blank([
'user_name' => $argv[2],
'user_type' => GDT_UserType::MEMBER,
])->insert();
GDT_Hook::callWithIPC('UserActivated', $user, null);
}
if (module_enabled('Login'))
{
$user->saveSettingVar('Login', 'password', BCrypt::create($argv[3])->__toString());
}
$user->saveVar('user_deleted', null);
$user->saveVar('user_deletor', null);
foreach (GDO_Permission::table()->all() as $perm)
{
GDO_UserPermission::grant($user, $perm->getName());
}
$user->changedPermissions();
echo t('msg_admin_created', [
$argv[2],
]) . "\n";
}
elseif (($command === 'wipe') && ($app->all))
{
Database::instance()->dropDatabase(GDO_DB_NAME);
Database::instance()->createDatabase(GDO_DB_NAME);
printf("The database has been killed completely and created empty.\n");
}
elseif ($command === 'wipe')
{
if ($argc !== 3)
{
printUsage(409, $command);
}
$module = ModuleLoader::instance()->loadModuleFS($argv[2]);
$response = Install::make()->executeWithInputs([
'module' => $module->getName(),
'uninstall' => '1',
], false);
if (Application::isError())
{
echo $response->renderCLI();
}
else
{
if ($classes = $module->getClasses())
{
$classes = array_map(function ($class)
{
return Strings::rsubstrFrom($class, '\\');
}, $classes);
}
else
{
$classes = [];
}
printf("The %s module has been wiped from the database.\n", $module->getName());
if ($classes)
{
printf("The following GDOs have been wiped: %s.\n", implode(', ', $classes));
}
}
}
elseif (($command === 'config') || ($command === 'conf'))
{
if (($argc < 2) || ($argc > 5))
{
printUsage();
}
$loader->initModules();
if ($argc === 2)
{
$modules = ModuleLoader::instance()->getEnabledModules();
$names = array_map(function (GDO_Module $module)
{
return $module->getName();
}, $modules);
echo t('msg_installed_modules', [
implode(', ', $names),
]) . '';
die(0);
}
if ($argc === 3)
{
$module = ModuleLoader::instance()->loadModuleFS($argv[2], false, true);
if ((!$module) || (!$module->isPersisted()))
{
echo t('err_module', [
html($argv[2]),
]) . "\n";
die(-1);
}
if ($config = $module->getConfigCache())
{
$vars = [];
foreach ($config as $key => $gdt)
{
$vars[] = $key;
}
$keys = implode(', ', $vars);
$keys = $keys ? $keys : t('none');
echo t('msg_available_config', [
$module->getName(),
$keys,
]);
echo PHP_EOL;
die(0);
}
else
{
echo t('msg_module_has_no_config');
die(1);
}
}
$key = $argv[3];
if ($argc === 4)
{
$module = ModuleLoader::instance()->loadModuleFS($argv[2], false, true);
if ((!$module) || (!$module->isPersisted()))
{
echo t('err_module_disabled', [
html($argv[2]),
]) . "\n";
die(-1);
}
$config = $module->getConfigColumn($key);
echo t('msg_set_config', [
$key,
$module->getName(),
$config->initial,
$config->gdoExampleVars(),
]);
echo PHP_EOL;
die(0);
}
$var = $argv[4];
if ($argc === 5)
{
$module = ModuleLoader::instance()->loadModuleFS($argv[2], false, true);
if ((!$module) || (!$module->isPersisted()))
{
echo t('err_module_disabled', [
html($argv[2]),
]) . "\n";
die(-1);
}
$gdt = $module->getConfigColumn($key)->var($var);
if (!$gdt->validate($gdt->toValue($var)))
{
echo json_encode($gdt->configJSON());
echo PHP_EOL;
die(1);
}
GDO_ModuleVar::createModuleVar($module, $gdt);
echo t('msg_changed_config',
[
$gdt->renderLabel(),
$module->getName(),
$gdt->displayVar($gdt->initial),
$gdt->displayVar($gdt->var),
]);
echo PHP_EOL;
Cache::flush();
GDT_Hook::callHook('ModuleVarsChanged', $module);
}
}
elseif ($command === 'provide')
{
$isme = $app->configured;
# command === 'provide_me';
$isall = $app->all;
$isssh = $app->ssh;
# $loader = ModuleLoader::instance();
# $loader->loadModules($isme, !$isme, true);
# Get all dependencies
$cd = 0;
if ($isall)
{
$deps = [
'Core',
];
foreach (ModuleProviders::$PROVIDERS as $name => $providers)
{
if ($providers)
{
$deps[] = $name;
}
}
}
elseif ($isme)
{
$deps = [];
foreach ($modules as $module)
{
$deps[] = $module->getModuleName();
}
}
else # Single
{
$deps = ModuleProviders::getDependencies($argv[2]);
if ($deps === null)
{
echo "Unknown module: {$argv[2]}\n";
die(-1);
}
$deps[] = 'Core';
$deps[] = $argv[2];
while ($cd != count($deps))
{
$cd = count($deps);
foreach ($deps as $dep)
{
if ($module = $loader->getModule($dep, false, false))
{
$moreDeps = $module->getDependencies();
}
else
{
$moreDeps = ModuleProviders::getDependencies($dep);
}
$deps = array_merge($deps, $moreDeps);
$deps = array_unique($deps);
}
}
}
$deps = array_unique($deps);
# Sort by name
sort($deps);
# Check missing in fs
$missing = [];
foreach ($deps as $dep)
{
if (!$loader->getModule($dep, true, false))
{
$missing[] = $dep;
}
}