From a91110e1f294fe12dbd65f897ea092f461298211 Mon Sep 17 00:00:00 2001 From: David Blankenship Date: Tue, 5 Sep 2023 15:00:59 -0400 Subject: [PATCH] fix(YALB-1550): remove drush command It's not needed due to the main project working on a command. Reference: https://www.drupal.org/project/single_content_sync/issues/3345288 --- .../Drush/Commands/YsStarterkitCommands.php | 199 ------------------ 1 file changed, 199 deletions(-) delete mode 100644 web/profiles/custom/yalesites_profile/modules/custom/ys_starterkit/src/Drush/Commands/YsStarterkitCommands.php diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_starterkit/src/Drush/Commands/YsStarterkitCommands.php b/web/profiles/custom/yalesites_profile/modules/custom/ys_starterkit/src/Drush/Commands/YsStarterkitCommands.php deleted file mode 100644 index 7bd8413e61..0000000000 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_starterkit/src/Drush/Commands/YsStarterkitCommands.php +++ /dev/null @@ -1,199 +0,0 @@ -contentFileGenerator = $contentFileGenerator; - $this->entityTypeManager = $entityTypeManager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('single_content_sync.file_generator'), - $container->get('entity_type.manager'), - ); - } - - /** - * Export content for use with starterkit importing. - * - * @usage ys_starterkit-exportContent - * Creates a zip file - * - * @command ys_starterkit:exportContent - * @aliases excon - */ - public function exportContent() { - $this->logger()->success('Exporting Nodes'); - $this->exportAllNodes(); - $this->logger()->success('Exporting Media'); - $this->exportAllMedia(); - $this->logger()->success('Exporting Taxonomy'); - $this->exportAllTaxonomy(); - } - - /** - * Export all node data. - * - * @usage ys_starterkit-exportAllNodes - * Creates a zip file - * - * @command ys_starterkit:exportAllNodes - * @aliases exNodes - */ - public function exportAllNodes() { - $zip_file = $this->exportNodes($this->getAllNodes()); - $zip_file = $this->renameZipFile($zip_file, 'nodes'); - - $this->logger()->success('Zip file created at: ' . $zip_file->getFileUri()); - } - - /** - * Export all media data. - * - * @usage ys_starterkit-exportAllNodes - * Creates a zip file - * - * @command ys_starterkit:exportAllNodes - * @aliases exNodes - */ - public function exportAllMedia() { - $zip_file = $this->exportNodes($this->getAllMedia()); - $zip_file = $this->renameZipFile($zip_file, 'media'); - - $this->logger()->success('Zip file created at: ' . $zip_file->getFileUri()); - } - - /** - * Exports all taxonomy terms. - * - * @usage ys_starterkit-exportAllTaxonomy - * - * @command ys_starterkit:exportAllTaxonomy - * @aliases exTax - */ - public function exportAllTaxonomy() { - $zip_file = $this->exportNodes($this->getAllTaxonomy()); - $zip_file = $this->renameZipFile($zip_file, 'taxonomy_terms'); - - $this->logger()->success('Zip file created at: ' . $zip_file->getFileUri()); - } - - /** - * Exports content for use with starterkit importing. - * - * @param array $nodes - * An array of entity types. - */ - protected function exportNodes(array $nodes) { - // Create a new ContentFileGenerator object from the container. - $zip_file = $this->contentFileGenerator->generateBulkZipFile($nodes, TRUE, TRUE); - - return $zip_file; - } - - /** - * Get all nodes. - * - * @return \Drupal\Core\Entity\EntityInterface[] - * An array of nodes. - */ - protected function getAllNodes() { - return $this->getAllEntitiesOfType('node'); - } - - /** - * Get all media. - * - * @return \Drupal\Core\Entity\EntityInterface[] - * An array of media entities. - */ - protected function getAllMedia() { - return $this->getAllEntitiesOfType('media'); - } - - /** - * Get all taxonomy terms. - * - * @return \Drupal\Core\Entity\EntityInterface[] - * An array of taxonomy terms. - */ - protected function getAllTaxonomy() { - return $this->getAllEntitiesOfType('taxonomy_term'); - } - - /** - * Get all entities of a given type. - * - * @param string $name - * The entity type name. - * - * @return \Drupal\Core\Entity\EntityInterface[] - * An array of entities. - */ - private function getAllEntitiesOfType(string $name) { - return $this->entityTypeManager->getStorage($name)->loadMultiple(); - } - - /** - * Rename a zip file. - * - * @param \Drupal\File\FileInterface $currentFile - * The current file. - * @param string $newName - * The new name. - * - * @return \Drupal\File\FileInterface - * The renamed file. - */ - private function renameZipFile(FileInterface $currentFile, string $newName) { - $newFileName = sprintf('%s-%s.zip', $newName, date('d_m_Y-H_i')); - $pathName = $currentFile->getFileUri(); - - $newPathName = str_replace($currentFile->getFilename(), $newFileName, $pathName); - rename($pathName, $newPathName); - - // Return a FileInterface of the new path name. - return File::create([ - 'uri' => $newPathName, - ]); - } - -}