PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.1.1
Kirki – Freeform Page Builder, Website Builder & Customizer v6.1.1
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Console / Commands / FreshCommand.php
kirki / libraries / framework / Console / Commands Last commit date
FreshCommand.php 3 weeks ago MakeClassCommand.php 3 weeks ago MakeControllerCommand.php 3 weeks ago MakeMigrationCommand.php 3 weeks ago MakeModelCommand.php 3 weeks ago MakeProviderCommand.php 3 weeks ago MakeRequestCommand.php 3 weeks ago MakeSeederCommand.php 3 weeks ago MigrateCommand.php 3 weeks ago SeedCommand.php 3 weeks ago
FreshCommand.php
116 lines
1 <?php
2
3 /**
4 * Drops all database tables and re-runs every pending migration from scratch.
5 * Combines schema reset with a full migrate pass for a clean development database.
6 * Intended for local or staging resets rather than production use.
7 *
8 * @package Framework
9 * @subpackage Console\Commands
10 * @since 1.0.0
11 */
12 namespace Kirki\Framework\Console\Commands;
13
14 \defined('ABSPATH') || exit;
15 use Kirki\Framework\Console\CommandBase;
16 use Kirki\Framework\Console\Synopsis;
17 use function Kirki\Framework\migrator;
18 class FreshCommand extends CommandBase
19 {
20 /**
21 * The sequential arguments
22 *
23 * @var array
24 *
25 * @since 1.0.0
26 */
27 protected $args;
28 /**
29 * The assoc arguments
30 *
31 * @var array
32 *
33 * @since 1.0.0
34 */
35 protected $assoc;
36 /**
37 * Run the command
38 *
39 * @param mixed $args The positional arguments.
40 * @param mixed $assoc The associative arguments.
41 *
42 * @return void
43 *
44 * @since 1.0.0
45 */
46 public function run($args, $assoc)
47 {
48 $this->args = $args;
49 $this->assoc = $assoc;
50 $this->fresh();
51 $this->run_migrations();
52 if ($this->need_seeding()) {
53 $this->run_seeder();
54 }
55 }
56 /**
57 * Fresh the database
58 *
59 * @return void
60 *
61 * @since 1.0.0
62 */
63 protected function fresh()
64 {
65 migrator()->fresh();
66 }
67 /**
68 * Run the migrations
69 *
70 * @return void
71 *
72 * @since 1.0.0
73 */
74 protected function run_migrations()
75 {
76 $command = new MigrateCommand();
77 $command->run([], []);
78 }
79 /**
80 * Run the seeder
81 *
82 * @return void
83 *
84 * @since 1.0.0
85 */
86 protected function run_seeder()
87 {
88 $command = new SeedCommand();
89 $args = [];
90 $assoc = ['class' => $this->assoc['class'] ?? null];
91 $command->run($args, $assoc);
92 }
93 /**
94 * Check if the database needs to be seeded
95 *
96 * @return bool
97 *
98 * @since 1.0.0
99 */
100 protected function need_seeding()
101 {
102 return !empty($this->assoc['seed']);
103 }
104 /**
105 * Prepare the command synopsis and metadata
106 *
107 * @return void
108 *
109 * @since 1.0.0
110 */
111 protected function prepare()
112 {
113 $this->summary('Drop all the tables and re-run all the migrations')->description("## EXAMPLES \n\n wp kirki db:fresh")->synopsis(Synopsis::type('assoc')->name('class')->description('The seeder class name')->optional())->synopsis(Synopsis::type('flag')->name('seed')->description('Seed the database')->optional());
114 }
115 }
116