diff --git a/.gitignore b/.gitignore index 96eb775..b0748b1 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ !/web/themes/custom/** /.idea/workspace.xml /vendor/ +/web/themes/custom/*/body-field-values.txt /web/themes/custom/*/dist/ diff --git a/web/modules/custom/custom/drush.services.yml b/web/modules/custom/custom/drush.services.yml new file mode 100644 index 0000000..455638b --- /dev/null +++ b/web/modules/custom/custom/drush.services.yml @@ -0,0 +1,6 @@ +services: + Drupal\custom\Command\ExportBodyValuesForThemePurgingCommand: + arguments: ['@database'] + autowire: true + tags: + - { name: drush.command } diff --git a/web/modules/custom/custom/src/Command/ExportBodyValuesForThemePurgingCommand.php b/web/modules/custom/custom/src/Command/ExportBodyValuesForThemePurgingCommand.php new file mode 100644 index 0000000..73c2353 --- /dev/null +++ b/web/modules/custom/custom/src/Command/ExportBodyValuesForThemePurgingCommand.php @@ -0,0 +1,49 @@ +database = $database; + } + + /** + * Drush command to export body field values into a file. + * + * @command opdavies:export-body-values-for-theme-purging + */ + public function handle() { + $values = Collection::make(self::$tableNames) + ->flatMap(fn(string $tableName) => $this->getValuesFromTable($tableName)) + ->implode(PHP_EOL); + + file_put_contents($this->getFilePath(), $values); + } + + private function getFilePath(): string { + return drupal_get_path('theme', 'opdavies') . DIRECTORY_SEPARATOR . $this->filename; + } + + private function getValuesFromTable(string $tableName): array { + return $this->database->select($tableName) + ->fields($tableName, ['body_value']) + ->execute() + ->fetchCol(); + } + +}