Skip to content

Commit

Permalink
NTO-1012 enable build --all-classes in production (#12)
Browse files Browse the repository at this point in the history
* allow `--all-classes` in production

* added default values for absent options

* additional protection around `execute()`
  • Loading branch information
akhumphrey authored Jun 30, 2024
1 parent 1140aa1 commit ef6ed6c
Showing 1 changed file with 49 additions and 45 deletions.
94 changes: 49 additions & 45 deletions lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineBuildTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ protected function configure()
$options = [
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
new sfCommandOption('all-classes', null, sfCommandOption::PARAMETER_NONE, 'Build all classes'),
];

if (!sfProjectConfiguration::getActive()->isProduction()) {
$options = array_merge($options, [
new sfCommandOption('no-confirmation', null, sfCommandOption::PARAMETER_NONE, 'Whether to force dropping of the database'),
new sfCommandOption('all', null, sfCommandOption::PARAMETER_NONE, 'Build everything and reset the database'),
new sfCommandOption('all-classes', null, sfCommandOption::PARAMETER_NONE, 'Build all classes'),
new sfCommandOption('model', null, sfCommandOption::PARAMETER_NONE, 'Build model classes'),
new sfCommandOption('forms', null, sfCommandOption::PARAMETER_NONE, 'Build form classes'),
new sfCommandOption('filters', null, sfCommandOption::PARAMETER_NONE, 'Build filter classes'),
Expand Down Expand Up @@ -130,7 +130,9 @@ protected function execute($arguments = [], $options = [])
throw new InvalidArgumentException(sprintf("You must include one or more of the following build options:\n--%s\n\nSee this task's help page for more information:\n\n php symfony help doctrine:build", join(', --', array_keys($this->getBuildOptions()))));
}

if (self::BUILD_DB == (self::BUILD_DB & $mode)) {
$is_production = sfProjectConfiguration::getActive()->isProduction();

if (!$is_production && (self::BUILD_DB == (self::BUILD_DB & $mode))) {
$task = new sfDoctrineDropDbTask($this->dispatcher, $this->formatter);
$task->setCommandApplication($this->commandApplication);
$task->setConfiguration($this->configuration);
Expand Down Expand Up @@ -185,61 +187,63 @@ protected function execute($arguments = [], $options = [])
}
}

if (self::BUILD_SQL == (self::BUILD_SQL & $mode)) {
$task = new sfDoctrineBuildSqlTask($this->dispatcher, $this->formatter);
$task->setCommandApplication($this->commandApplication);
$task->setConfiguration($this->configuration);
$ret = $task->run();
if (!$is_production) {
if (self::BUILD_SQL == (self::BUILD_SQL & $mode)) {
$task = new sfDoctrineBuildSqlTask($this->dispatcher, $this->formatter);
$task->setCommandApplication($this->commandApplication);
$task->setConfiguration($this->configuration);
$ret = $task->run();

if ($ret) {
return $ret;
if ($ret) {
return $ret;
}
}
}

if ($options['and-migrate']) {
$task = new sfDoctrineMigrateTask($this->dispatcher, $this->formatter);
$task->setCommandApplication($this->commandApplication);
$task->setConfiguration($this->configuration);
$ret = $task->run();
if ($options['and-migrate'] ?? false) {
$task = new sfDoctrineMigrateTask($this->dispatcher, $this->formatter);
$task->setCommandApplication($this->commandApplication);
$task->setConfiguration($this->configuration);
$ret = $task->run();

if ($ret) {
return $ret;
}
} elseif (self::BUILD_DB == (self::BUILD_DB & $mode)) {
$task = new sfDoctrineInsertSqlTask($this->dispatcher, $this->formatter);
$task->setCommandApplication($this->commandApplication);
$task->setConfiguration($this->configuration);
$ret = $task->run();
if ($ret) {
return $ret;
}
} elseif (self::BUILD_DB == (self::BUILD_DB & $mode)) {
$task = new sfDoctrineInsertSqlTask($this->dispatcher, $this->formatter);
$task->setCommandApplication($this->commandApplication);
$task->setConfiguration($this->configuration);
$ret = $task->run();

if ($ret) {
return $ret;
if ($ret) {
return $ret;
}
}
}

if (count($options['and-load']) || count($options['and-append'])) {
$task = new sfDoctrineDataLoadTask($this->dispatcher, $this->formatter);
$task->setCommandApplication($this->commandApplication);
$task->setConfiguration($this->configuration);
if (count($options['and-load'] ?? []) || count($options['and-append'] ?? [])) {
$task = new sfDoctrineDataLoadTask($this->dispatcher, $this->formatter);
$task->setCommandApplication($this->commandApplication);
$task->setConfiguration($this->configuration);

if (count($options['and-load'])) {
$ret = $task->run([
'dir_or_file' => in_array([], $options['and-load'], true) ? null : $options['and-load'],
]);
if (count($options['and-load'])) {
$ret = $task->run([
'dir_or_file' => in_array([], $options['and-load'], true) ? null : $options['and-load'],
]);

if ($ret) {
return $ret;
if ($ret) {
return $ret;
}
}
}

if (count($options['and-append'])) {
$ret = $task->run([
'dir_or_file' => in_array([], $options['and-append'], true) ? null : $options['and-append'],
], [
'append' => true,
]);
if (count($options['and-append'] ?? [])) {
$ret = $task->run([
'dir_or_file' => in_array([], $options['and-append'], true) ? null : $options['and-append'],
], [
'append' => true,
]);

if ($ret) {
return $ret;
if ($ret) {
return $ret;
}
}
}
}
Expand Down

0 comments on commit ef6ed6c

Please sign in to comment.