Ejemplo n.º 1
0
 public function testCanPromptConfirmWithYesNoCharChangedWithSetter()
 {
     fwrite($this->adapter->stream, 'oaB');
     $confirm = new Confirm("Is ZF2 the best framework ?", "1", "0");
     $confirm->setYesChar("A");
     $confirm->setNoChar("B");
     $confirm->setEcho(false);
     $confirm->setConsole($this->adapter);
     ob_start();
     $response = $confirm->show();
     $text = ob_get_clean();
     $this->assertEquals($text, "Is ZF2 the best framework ?\n");
     $this->assertTrue($response);
 }
Ejemplo n.º 2
0
 /**
  * @param $templateFromConfig
  * @param $console
  * @param $destination
  * @param $variables
  */
 protected function templateApply($templateFromConfig, $console, $destination, $variables)
 {
     $config = $this->getServiceLocator()->get('config');
     $templatePath = getcwd() . $config['generators']['path'] . $templateFromConfig;
     if (!file_exists($templatePath)) {
         $console->writeLine('Template file not exists: ' . $templatePath, color::RED);
         return;
     }
     $template = file_get_contents($templatePath);
     $destination .= '/' . substr($templateFromConfig, 0, -4) . 'php';
     foreach ($variables as $variableName => $variableValue) {
         $template = str_replace('$' . $variableName . '$', $variableValue, $template);
         //lower case variable
         $template = str_replace('&' . $variableName . '&', lcfirst($variableValue), $template);
         $destination = str_replace('$' . $variableName . '$', $variableValue, $destination);
     }
     $destinationDir = dirname($destination);
     if (!is_dir($destinationDir)) {
         mkdir($destinationDir, 0777, true);
     }
     $rewrite = 'y';
     if (file_exists($destination)) {
         $rewrite = Prompt\Confirm::prompt('File is exists. Are you want to rewrite file? [y/n]', 'y', 'n');
     }
     if ($rewrite == 'y') {
         file_put_contents($destination, $template);
         $console->writeLine('The class generated: ' . $destination, color::GREEN);
     }
 }
Ejemplo n.º 3
0
 /**
  * Show confirm for migration
  *
  * @param string $action
  * @param string $migration
  * @param array $migrationArray
  * @return bool
  */
 protected function applyMigration($action, $migration, $migrationArray)
 {
     /* @var $adapter \Zend\Db\Adapter\Adapter */
     /* @var $console Console */
     $adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     $console = $this->getServiceLocator()->get('console');
     $model = new Migration($adapter);
     $methodName = $action == self::UPGRADE_KEY ? 'upgrade' : 'downgrade';
     $console->writeLine();
     $console->write('Current migration: ');
     $console->writeLine($this->getMigrationFolder() . $migration . '.php', Color::YELLOW);
     $console->writeLine($migrationArray[$action], Color::BLUE);
     if (Confirm::prompt('Apply this migration? [y/n]', 'y', 'n')) {
         $model->{$methodName}($migration, $migrationArray);
         if ($action == self::UPGRADE_KEY) {
             $console->writeLine('This migration successful upgraded', Color::GREEN);
         } else {
             $console->writeLine('This migration successful downgraded', Color::GREEN);
         }
     } else {
         $console->writeLine('This migration discarded', Color::RED);
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
 public function passwordAction()
 {
     $request = $this->getRequest();
     // Make sure that we are running in a console and the user has not
     // tricked our
     // application into running this action from a public web server.
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('You can only use this action from a console!');
     }
     // Get user email from console and check if the user used --verbose or
     // -v flag
     $userEmail = $request->getParam('userEmail');
     $verbose = $request->getParam('verbose');
     // reset new password
     $newPassword = Rand::getString(16);
     $console = Console::getInstance();
     if (Confirm::prompt('Is this the correct answer? [y/n]', 'y', 'n')) {
         $console->write("You chose YES\n");
     } else {
         $console->write("You chose NO\n");
     }
     if (!$verbose) {
         return "Done! {$userEmail} has received an email with his new password.\n";
     } else {
         return "Done! New password for user {$userEmail} is '{$newPassword}'. It has also been emailed to him. \n";
     }
 }
 public function upAction()
 {
     $available = $this->migrationService->getAvailableMigrations();
     $this->console->writeLine(' Available migrations:');
     if (!$this->showMigrationList($available)) {
         return;
     }
     try {
         if ($oneMigration = $this->getRequest()->getParam('migration', null)) {
             if (isset($available[$oneMigration])) {
                 $this->migrationService->installMigration($oneMigration, $this->interactive);
             } else {
                 $this->console->writeLine(sprintf(' "%s" migration not available.', $oneMigration), ColorInterface::RED);
             }
         } else {
             if (!$this->interactive || Confirm::prompt(' Install available migration? [y/n] ')) {
                 foreach ($available as $name => $migration) {
                     $this->migrationService->installMigration($name);
                 }
             } else {
                 $this->console->writeLine(' Migration process stopped by user.', ColorInterface::GREEN);
             }
         }
     } catch (StopMigrationException $e) {
         $this->console->writeLine($e->getMessage(), ColorInterface::RED);
     }
 }
Ejemplo n.º 6
0
 /**
  * Prompt the user for config values, and create the config file.
  */
 public function ConfigAction()
 {
     //does the config file exist?
     if (file_exists($this->configFile) and !Prompt\Confirm::prompt('Config file exists, continue? (y/n) ')) {
         return;
     }
     $dist = (require $this->configDist);
     $values = $this->collectValues($dist);
     file_put_contents($this->configFile, '<?php' . PHP_EOL . 'return ' . var_export($values, true) . ';');
     echo "Config saved." . PHP_EOL;
 }
Ejemplo n.º 7
0
 /**
  * Interactive database setup.
  * WILL OUTPUT VIA CONSOLE!
  *
  * @param  boolean $overwrite Overwrite existing config
  * @return string
  */
 public function setup($overwrite = false)
 {
     /**
      * Output console usage
      */
     if (!$this->console) {
         throw new \RuntimeException('You can only use this action from a console!');
     }
     $this->console->writeLine("ZF2 Phinx Module - Interactive Setup", self::GREEN);
     /**
      * Check for existing config
      */
     $zfConfig = $this->config['phinx-module']['zf2-config'];
     $phinxConfig = $this->config['phinx-module']['phinx-config'];
     if (!$overwrite && (file_exists($zfConfig) || file_exists($phinxConfig))) {
         if (file_exists($zfConfig) && !file_exists($phinxConfig)) {
             $this->sync();
             $this->console->writeLine("ZF2 Config found but Phinx config missing => Config Synced.");
         } else {
             $this->console->writeLine("Existing config file(s) found, unable to continue!", self::LIGHT_RED);
             $this->console->writeLine("Use the --overwrite flag to replace existing config.", self::LIGHT_RED);
         }
         return;
     }
     /**
      * Ask questions
      */
     $loop = true;
     while ($loop) {
         $this->console->writeLine("MySQL Database connection details:");
         $host = Prompt\Line::prompt("Hostname? [localhost] ", true) ?: 'localhost';
         $port = Prompt\Line::prompt("Port? [3306] ", true) ?: 3306;
         $user = Prompt\Line::prompt("Username? ");
         $pass = Prompt\Line::prompt("Password? ");
         $dbname = Prompt\Line::prompt("Database name? ");
         $loop = !Prompt\Confirm::prompt("Save these details? [y/n]");
     }
     /**
      * Build config
      */
     $config = new Config(array('db' => array('dsn' => "mysql:host={$host};dbname={$dbname}", 'username' => $user, 'password' => $pass, 'port' => $port)));
     $writer = new PhpArray();
     $writer->toFile($zfConfig, $config);
     $this->console->writeLine();
     $this->console->writeLine("ZF2 Config file written: {$zfConfig}");
     /**
      * Write Phinx config
      */
     $migrations = $this->config['phinx-module']['migrations'];
     $this->writePhinxConfig('mysql', $host, $user, $pass, $dbname, $port, $migrations);
     $this->console->writeLine("Phinx Config file written: {$phinxConfig}");
 }
 /**
  * {@inheritdoc}
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     parent::dispatch($request, $response);
     /* @var $request \Zend\Console\Request */
     /* @var $response \Zend\Console\Response */
     $consumerName = $request->getParam('consumer-name');
     $consumerManager = $this->getConsumerManager();
     if (!$consumerManager->has($consumerName)) {
         $this->getConsole()->writeLine('ERROR: Consumer "' . $consumerName . '" not found', ColorInterface::RED);
         $response->setErrorLevel(1);
         return;
     }
     $confirm = new Prompt\Confirm('Are you sure you want to purge? [y/n]', 'y', 'n');
     $confirm->setConsole($this->getConsole());
     if ($request->getParam('no-confirmation', false) || $confirm->show()) {
         $consumer = $consumerManager->get($consumerName);
         $consumer->purge();
         $this->getConsole()->writeLine('OK', ColorInterface::GREEN);
     } else {
         $this->getConsole()->writeLine('Purging cancelled!', ColorInterface::YELLOW);
     }
 }
 public function consoleModuleAction()
 {
     $request = $this->getRequest();
     // Make sure that we are running in a console and the user has not tricked our
     // application into running this action from a public web server.
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('You can only use this action from a console!');
     }
     $module = $request->getParam('moduleName');
     $entity = $request->getParam('tableName');
     $entitymanager = $request->getParam('entityManager');
     if ($module == false) {
         $module = Line::prompt('Please Enter the Name of the Module: ', false, 100);
     }
     if ($entity == false) {
         $entity = Line::prompt('Please Enter the Name of the The Table, the Module should be created from: ', false, 100);
     }
     if ($entitymanager == false) {
         $entitymanager = Line::prompt('Please Enter a entity-manager (default:doctrine.entitymanager.orm_default): ', true, 100);
         // If no entitymanager given, we set an default
         if ($entitymanager == false) {
             $entitymanager = 'doctrine.entitymanager.orm_default';
         }
     }
     // Check on a valid entitymanager
     $em = $this->getServiceLocator()->get($entitymanager);
     if (!is_a($em, 'Doctrine\\ORM\\EntityManager')) {
         return 'Exit: Invalid Entitymanager';
     }
     $filepath = 'module/' . $module;
     if (is_dir($filepath)) {
         if (!Confirm::prompt('Module filepath exists. Overwrite? [y/n]', 'y', 'n')) {
             return 'EXIT: Module exists.';
         }
     }
     if (!is_dir($filepath) and !mkdir($filepath, 0777, true)) {
         return 'EXIT: Directory could not be created.';
     }
     // All Validated, we generate now.
     $this->setEntitymanager($entitymanager);
     $this->setFilepath($filepath);
     $this->setNamespace($module);
     $this->setTables(array($entity));
     $this->generate();
     return 'Module successfully created';
 }
 public function updateAction()
 {
     $config = $this->config['zf-oauth2-doctrine']['default'];
     $console = $this->console;
     $objectManager = $this->objectManager;
     // Make sure that we are running in a console and the user has not tricked our
     // application into running this action from a public web server.
     $request = $this->getRequest();
     if (!$request instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console.');
     }
     $scopeEntity = $objectManager->getRepository($config['mapping']['Scope']['entity'])->find($this->getRequest()->getParam('id'));
     // Get the Scope
     $console->write("Current Value: " . $scopeEntity->getScope() . "\n", Color::CYAN);
     $scope = Prompt\Line::prompt("Scope: ", false);
     $scopeEntity->setScope($scope);
     $currentDefault = $scopeEntity->getIsDefault() ? 'Y' : 'N';
     $console->write("Current Value: " . $currentDefault . "\n", Color::CYAN);
     $default = Prompt\Confirm::prompt('Is this a default scope? [y/n] ', 'y', 'n');
     $scopeEntity->setIsDefault($default == 'y');
     $objectManager->flush();
     $console->write("Scope updated\n", Color::GREEN);
 }
Ejemplo n.º 11
0
 /**
  * Import Search Results
  *
  * @throws \RuntimeException
  */
 public function importAction()
 {
     if (!$this->getRequest() instanceof ConsoleRequest) {
         throw new \RuntimeException('You can only use this action from a console!');
     }
     $filter = $this->inputFilterSearch;
     $filter->setData($this->params()->fromRoute());
     if ($filter->isValid() && $filter->getValue('help') == null) {
         if ($filter->getValue('confirm') == 'yes') {
             $confirm = new Confirm('Are you sure you want to Import Search Results? [y/n]', 'y', 'n');
             $result = $confirm->show();
         } else {
             $result = true;
         }
         if ($result) {
             $this->serviceSearch->import();
         }
     } else {
         if ($filter->getValue('help') != null) {
             $this->getEventManager()->trigger('Mp3Help', null, ['help' => 'import']);
             exit;
         }
     }
 }
Ejemplo n.º 12
0
 public function uninstallMigration($migrationName, $interactive = false)
 {
     if (!isset($this->installedMigrations[$migrationName])) {
         return;
     }
     if ($interactive && !Confirm::prompt(sprintf(' Uninstall "%s" migration? [y/n] ', $migrationName))) {
         throw new StopMigrationException(' Uninstalling migrations canceled by user.');
     }
     $sql = new Sql($this->adapter);
     $query = $sql->select(['d' => $this->dependsTable])->columns([])->join(['m' => $this->migrationTable], 'm.id = d.child_id', ['name'])->where(['d.parent_id' => $this->installedMigrations[$migrationName]['id']])->order(['m.installation_date' => Select::ORDER_DESCENDING]);
     $statement = $sql->prepareStatementForSqlObject($query);
     $children = [];
     foreach ($statement->execute() as $migration) {
         $children[] = $migration['name'];
     }
     array_map([$this, __FUNCTION__], $children);
     $this->removeMigration($this->installedMigrations[$migrationName]['instance']);
 }
Ejemplo n.º 13
0
 /**
  * @param $question
  * @param ConsoleAdapter $console
  *
  * @return bool
  */
 private function askBooleanQuestion($question, ConsoleAdapter $console)
 {
     $console->write($question . ' ', ColorInterface::CYAN);
     $console->writeLine('[y/n]', ColorInterface::GREEN);
     $prompt = new Confirm('');
     $prompt->setConsole($console);
     return (bool) $prompt->show();
 }
Ejemplo n.º 14
0
 public function confirm($promptText, $echo = true)
 {
     $prompt = new ConfirmPrompt($promptText);
     $prompt->setEcho($echo);
     $prompt->setConsole($this->console);
     return $prompt->show();
 }
 public function consoleEntityAction()
 {
     $request = $this->getRequest();
     // Make sure that we are running in a console and the user has not tricked our
     // application into running this action from a public web server.
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('You can only use this action from a console!');
     }
     $all = $request->getParam('all');
     $entity = $request->getParam('entityName');
     $namespace = $request->getParam('namespace');
     $filepath = $request->getParam('dir');
     $entitymanager = $request->getParam('entityManager');
     // If we have no Parameters given, well ask the user
     if (!isset($entity) and $all === false) {
         $char = Char::prompt('Do you want do create one Model (o) or All Models (a)?', 'ao', true, false, true);
         if ($char == 'o') {
             $entity = Line::prompt('Please Enter the Name of the Entity to be created: ', false, 100);
         } else {
             $all = true;
         }
     }
     if ($namespace == false) {
         $namespace = Line::prompt('Please Enter the Name of Namespace to be used: ', false, 100);
     }
     if ($filepath == false) {
         $filepath = Line::prompt('Please Enter a File-Path for the Entity-Files: (std: "Entities") ', true, 100);
         // If no filepath given, we set an default filepath
         if (empty($filepath)) {
             $filepath = 'Entities';
         }
     }
     if (!is_dir($filepath)) {
         if (Confirm::prompt('Directory ' . $filepath . ' does not exist. Create? [y/n]', 'y', 'n')) {
             if (!mkdir($filepath, 0777, true)) {
                 return 'EXIT: Directory could not be created.';
             }
         } else {
             return 'EXIT: Invalid Directory.';
         }
     }
     if ($entitymanager == false) {
         $entitymanager = Line::prompt('Please Enter a entity-manager (default:doctrine.entitymanager.orm_default): ', true, 100);
         // If no entitymanager given, we set an default
         if ($entitymanager == false) {
             $entitymanager = 'doctrine.entitymanager.orm_default';
         }
     }
     // Check on a valid entitymanager
     try {
         $em = $this->getServiceLocator()->get($entitymanager);
         if (!is_a($em, 'Doctrine\\ORM\\EntityManager')) {
             throw new ServiceNotFoundException();
         }
     } catch (ServiceNotFoundException $e) {
         return 'Exit: Invalid Entitymanager';
     }
     // All Validated, we generate now.
     $this->setEntitymanager($entitymanager);
     $this->setFilepath($filepath);
     $this->setNamespace($namespace);
     if ($all === true) {
         $tables = array();
     } else {
         $tables = array($entity);
     }
     $this->setTables($tables);
     $this->generate();
     return 'Files successfully created' . "\n";
 }
Ejemplo n.º 16
0
 public function clearAction()
 {
     $cache = $this->getCache();
     $console = $this->getConsole();
     $clear = $this->params('clear');
     $flush = $this->params('flush');
     $force = $this->params('force') || $this->params('f');
     if ($flush === true) {
         if (!$force) {
             if (!ConsoleConfirm::prompt('Are you sure to flush the cache? [y/n] ')) {
                 $console->writeLine('Not flushing cache');
                 return;
             }
         }
         $cache->flush();
         $console->writeLine('Cache flushed');
         return;
     }
     if ($clear === true) {
         if (!$force) {
             if (!ConsoleConfirm::prompt('Are you sure to clear the cache? [y/n] ')) {
                 $console->writeLine('Not clearing cache');
                 return;
             }
         }
         if ($this->params('expired') || $this->params('e')) {
             if (!$cache instanceof ClearExpiredInterface) {
                 $console->writeLine(sprintf('Cache does not support to clear expired items'), Color::WHITE, Color::RED);
                 return;
             }
             $cache->clearExpired();
             $console->writeLine('Cache cleared from expired items');
             return;
         }
         $namespace = $this->params('by-namespace', false);
         if ($namespace) {
             if (!$cache instanceof ClearByNamespaceInterface) {
                 $console->writeLine(sprintf('Cache does not support to clear by namespace'), Color::WHITE, Color::RED);
                 return;
             }
             $cache->clearByNamespace($namespace);
             $console->writeLine('Cache cleared all items namespaced with ' . $namespace);
             return;
         }
         $prefix = $this->params('by-prefix', false);
         if ($prefix) {
             if (!$cache instanceof ClearByPrefixInterface) {
                 $console->writeLine(sprintf('Cache does not support to clear by prefix'), Color::WHITE, Color::RED);
                 return;
             }
             $cache->clearByPrefix($prefix);
             $console->writeLine('Cache cleared all items prefixed with ' . $prefix);
             return;
         }
         $tag = $this->params('by-tag', false);
         if ($tag) {
             //  $console->writeLine(var_dump($cache));
             if (!$cache instanceof TaggableInterface) {
                 $console->writeLine(sprintf('Cache does not support to clear by tag'), Color::WHITE, Color::RED);
                 return;
             }
             $cache->clearByTags(array($tag));
             $console->writeLine('Cache cleared all items tag with ' . $prefix);
             return;
         }
     }
 }
Ejemplo n.º 17
0
 /**
  * Generate report about unsed files and lost data in database
  */
 public function reportUnusedFilesAction()
 {
     // get params
     if ($this->getRequest()->getParam('only-locations-images')) {
         $this->onlyLocationImages = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-building-maps')) {
         $this->onlyBuildingMaps = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-office-maps')) {
         $this->onlyOfficeMaps = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-profiles-images')) {
         $this->onlyProfileImages = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-apartments-images')) {
         $this->onlyApartmentImages = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-blog-images')) {
         $this->onlyBlogImages = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-documents')) {
         $this->onlyDocuments = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-purchase-order-attachments')) {
         $this->onlyPurchaseOrder = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-purchase-order-item-attachments')) {
         $this->onlyPurchaseOrderItems = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-users-documents')) {
         $this->onlyUsersDocuments = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-jobs-documents')) {
         $this->onlyJobsDocuments = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-booking-documents')) {
         $this->onlyBookingDocuments = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-money-account-documents')) {
         $this->onlyMoneyAccountDocuments = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-task-attachments')) {
         $this->onlyTaskAttachments = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-parking-attachments')) {
         $this->onlyParkingAttachments = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('only-apartel-images')) {
         $this->onlyApartelImages = true;
         $this->withOutParams = false;
     }
     if ($this->getRequest()->getParam('remove-from-disk')) {
         $this->removeFromDisk = true;
     }
     $table = new Table(['columnWidths' => [4, 71, 71]]);
     $table->appendRow(['#', 'on Disk', 'on Database']);
     // array of unused files in disk - for delete it!
     $unusedFiles = [];
     /**
      * Locations
      */
     if ($this->onlyLocationImages or $this->withOutParams) {
         $locationImagesPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_LOCATIONS_PATH;
         if (!is_readable($locationImagesPath)) {
             echo "Folder does not exist: " . $locationImagesPath . PHP_EOL . PHP_EOL;
         } else {
             $locationsDiskData = array_diff(scandir($locationImagesPath), ['.', '..']);
             $locationsDiskArray = [];
             foreach ($locationsDiskData as $locationDisk) {
                 $thisFilesList = array_diff(scandir($locationImagesPath . $locationDisk), ['.', '..']);
                 foreach ($thisFilesList as $file) {
                     $locationsDiskArray[$locationDisk][] = $file;
                 }
             }
             $locationsDbData = $this->getLocationsData();
             foreach ($locationsDbData as $locationDb) {
                 $cover_image = $locationImagesPath . $locationDb->getId() . '/' . $locationDb->getCover_image();
                 $thumbnail = $locationImagesPath . $locationDb->getId() . '/' . $locationDb->getThumbnail();
                 if (!empty($locationDb->getCover_image()) && $locationDb->getCover_image() !== null && !is_file($cover_image)) {
                     $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_LOCATION_DETAILS . '.id: ' . $locationDb->getId() . PHP_EOL . 'name: ' . $locationDb->getName() . PHP_EOL . 'cover_image: ' . PHP_EOL . $cover_image]);
                 } elseif (!empty($locationDb->getCover_image()) && $locationDb->getCover_image() !== null) {
                     $filename = explode('_', $locationDb->getCover_image())[0];
                     foreach ($locationsDiskArray[$locationDb->getId()] as $locationFileKey => $locationFile) {
                         if (strstr($locationFile, $filename)) {
                             unset($locationsDiskArray[$locationDb->getId()][$locationFileKey]);
                         }
                     }
                 }
                 if (!empty($locationDb->getThumbnail()) && $locationDb->getThumbnail() !== null && !is_file($thumbnail)) {
                     $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_LOCATION_DETAILS . '.id: ' . $locationDb->getId() . PHP_EOL . 'name: ' . $locationDb->getName() . PHP_EOL . 'thumbnail: ' . PHP_EOL . $thumbnail]);
                 } elseif (!empty($locationDb->getThumbnail()) && $locationDb->getThumbnail() !== null) {
                     $filename = explode('_', $locationDb->getThumbnail())[0];
                     foreach ($locationsDiskArray[$locationDb->getId()] as $locationFileKey => $locationFile) {
                         if (strstr($locationFile, $filename)) {
                             unset($locationsDiskArray[$locationDb->getId()][$locationFileKey]);
                         }
                     }
                 }
             }
             foreach ($locationsDiskArray as $folder => $locationDisk) {
                 foreach ($locationDisk as $locationDiskFiles) {
                     $unusedLocationFile = $locationImagesPath . $folder . '/' . $locationDiskFiles;
                     $unusedFiles[] = $unusedLocationFile;
                     if (is_dir($unusedLocationFile)) {
                         $table->appendRow([$this->runCounter(), 'type: Location' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedLocationFile, 'x']);
                     } else {
                         $table->appendRow([$this->runCounter(), 'type: Location' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedLocationFile, 'x']);
                     }
                 }
             }
         }
     }
     /**
      * Profiles
      */
     if ($this->onlyProfileImages or $this->withOutParams) {
         $profileImagesPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_PROFILE_PATH;
         if (!is_readable($profileImagesPath)) {
             echo "Folder does not exist: " . $profileImagesPath . PHP_EOL . PHP_EOL;
         } else {
             $profilesDiskData = array_diff(scandir($profileImagesPath), ['.', '..']);
             $profilesDiskArray = [];
             foreach ($profilesDiskData as $profileDisk) {
                 $thisFilesList = array_diff(scandir($profileImagesPath . $profileDisk . '/'), ['.', '..']);
                 foreach ($thisFilesList as $file) {
                     $profilesDiskArray[$profileDisk][] = $file;
                 }
             }
             $profilesDbData = $this->getProfilesData();
             foreach ($profilesDbData as $profileDb) {
                 $avatar = $profileImagesPath . $profileDb->getId() . '/' . $profileDb->getAvatar();
                 if (!empty($profileDb->getAvatar()) and $profileDb->getAvatar() !== null and !is_file($avatar)) {
                     $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_BACKOFFICE_USERS . '.id: ' . $profileDb->getId() . PHP_EOL . 'user name: ' . $profileDb->getFirstName() . ' ' . $profileDb->getLastName() . PHP_EOL . 'avatar: ' . PHP_EOL . $avatar]);
                 } elseif (!empty($profileDb->getAvatar()) and $profileDb->getAvatar() !== null) {
                     $filename = explode('_', $profileDb->getAvatar())[0];
                     foreach ($profilesDiskArray[$profileDb->getId()] as $profileFileKey => $profileFile) {
                         if (strstr($profileFile, $filename)) {
                             unset($profilesDiskArray[$profileDb->getId()][$profileFileKey]);
                         }
                     }
                 }
             }
             foreach ($profilesDiskArray as $folder => $profileDisk) {
                 foreach ($profileDisk as $profileDiskFiles) {
                     $unusedProfileFile = $profileImagesPath . $folder . '/' . $profileDiskFiles;
                     $unusedFiles[] = $unusedProfileFile;
                     if (is_dir($unusedProfileFile)) {
                         $table->appendRow([$this->runCounter(), 'type: Profile' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedProfileFile, 'x']);
                     } else {
                         $table->appendRow([$this->runCounter(), 'type: Profile' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedProfileFile, 'x']);
                     }
                 }
             }
         }
     }
     /**
      * Apartment Images
      */
     if ($this->onlyApartmentImages or $this->withOutParams) {
         $apartmentImagesPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_APARTMENT;
         if (!is_readable($apartmentImagesPath)) {
             echo "Folder does not exist: " . $apartmentImagesPath . PHP_EOL . PHP_EOL;
         } else {
             $apartmentsDiskData = array_diff(scandir($apartmentImagesPath), ['.', '..']);
             $apartmentsDiskArray = [];
             foreach ($apartmentsDiskData as $apartmentDisk) {
                 $thisFilesList = array_diff(scandir($apartmentImagesPath . $apartmentDisk . '/'), ['.', '..']);
                 foreach ($thisFilesList as $file) {
                     $apartmentsDiskArray[$apartmentDisk][] = $file;
                 }
             }
             $apartmentsDbData = $this->getApartmentsData();
             foreach ($apartmentsDbData as $apartmentDb) {
                 $dbImageResult = [];
                 $apartmentThumbsSizes = ['445', '555', '780', '96'];
                 if (isset($apartmentsDiskArray[$apartmentDb->getApartmentId()]) && count($apartmentsDiskArray[$apartmentDb->getApartmentId()])) {
                     for ($i = 1; $i <= 32; $i++) {
                         $imgId = 'img' . $i;
                         $getImgActionId = 'getImg' . $i;
                         if (!empty($apartmentDb->{$getImgActionId}()) and $apartmentDb->{$getImgActionId}() !== null) {
                             $dbImageResult[$i]['has_original'] = false;
                             $dbImageResult[$i]['has_thumbs'] = [];
                             $filenameFromDb = explode('/', $apartmentDb->{$getImgActionId}())[3];
                             $fileOriginNameFromDb = explode('orig', $filenameFromDb)[0];
                             foreach ($apartmentsDiskArray[$apartmentDb->getApartmentId()] as $apartmentFileKey => $apartmentFile) {
                                 foreach ($apartmentThumbsSizes as $size) {
                                     if (strstr($apartmentFile, $fileOriginNameFromDb . $size)) {
                                         unset($apartmentsDiskArray[$apartmentDb->getApartmentId()][$apartmentFileKey]);
                                         $dbImageResult[$i]['has_thumbs'][] = $size;
                                     }
                                 }
                                 if ($apartmentFile == $filenameFromDb) {
                                     unset($apartmentsDiskArray[$apartmentDb->getApartmentId()][$apartmentFileKey]);
                                     $dbImageResult[$i]['has_original'] = $apartmentDb->{$getImgActionId}();
                                 }
                             }
                         }
                     }
                     foreach ($dbImageResult as $imgId => $imgValues) {
                         $doesNotHaveThis = '';
                         $getImgActionId = 'getImg' . $imgId;
                         if (!$imgValues['has_original']) {
                             $doesNotHaveThis .= PHP_EOL . 'original: ' . substr($apartmentImagesPath, 0, -1) . $apartmentDb->{$getImgActionId}();
                         }
                         $hasNoThumb = array_diff($apartmentThumbsSizes, $imgValues['has_thumbs']);
                         if (count($hasNoThumb)) {
                             $filenameFromDb = explode('/', $apartmentDb->{$getImgActionId}())[3];
                             $fileOriginNameFromDb = explode('orig', $filenameFromDb)[0];
                             foreach ($hasNoThumb as $thumbSize) {
                                 $thumsImagePath = $apartmentImagesPath . $apartmentDb->getApartmentId() . '/' . $fileOriginNameFromDb . $thumbSize . '.jpg';
                                 $doesNotHaveThis .= PHP_EOL . 'thumb: ' . $thumsImagePath;
                             }
                         }
                         if (!empty($doesNotHaveThis)) {
                             $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_APARTMENT_IMAGES . '.apartment_id: ' . $apartmentDb->getApartmentId() . PHP_EOL . $imgId . ': ' . $doesNotHaveThis]);
                         }
                     }
                 } elseif (!empty($apartmentDb->getImg1())) {
                     $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_APARTMENT_IMAGES . '.apartment_id: ' . $apartmentDb->getApartmentId() . PHP_EOL . '!!!' . PHP_EOL . 'Apartment images folder empty or not exist' . PHP_EOL . 'But apartment has attached images in database']);
                 }
             }
             foreach ($apartmentsDiskArray as $folder => $apartmentDisk) {
                 foreach ($apartmentDisk as $apartmentDiskFiles) {
                     if ($apartmentDiskFiles === 'map') {
                         continue;
                     }
                     $unusedApartmentImagesFile = $apartmentImagesPath . $folder . '/' . $apartmentDiskFiles;
                     $unusedFiles[] = $unusedApartmentImagesFile;
                     if (is_dir($unusedApartmentImagesFile)) {
                         $table->appendRow([$this->runCounter(), 'type: Apartment' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedApartmentImagesFile, 'x']);
                     } else {
                         $table->appendRow([$this->runCounter(), 'type: Apartment' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedApartmentImagesFile, 'x']);
                     }
                 }
             }
         }
     }
     /**
      * Documents
      */
     if ($this->onlyDocuments or $this->withOutParams) {
         $documentUploadsPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_DOCUMENTS;
         if (!is_readable($documentUploadsPath)) {
             echo "Folder does not exist: " . $documentUploadsPath . PHP_EOL . PHP_EOL;
         } else {
             $docsDiskData = array_diff(scandir($documentUploadsPath), ['.', '..']);
             $docsDiskArray = [];
             foreach ($docsDiskData as $docDiskYear) {
                 $yearFilesList = array_diff(scandir($documentUploadsPath . $docDiskYear), ['.', '..']);
                 foreach ($yearFilesList as $docDiskMonth) {
                     $monthFilesList = array_diff(scandir($documentUploadsPath . $docDiskYear . '/' . $docDiskMonth), ['.', '..']);
                     foreach ($monthFilesList as $docDiskDay) {
                         $dayFilesList = array_diff(scandir($documentUploadsPath . $docDiskYear . '/' . $docDiskMonth . '/' . $docDiskDay), ['.', '..']);
                         foreach ($dayFilesList as $file) {
                             $docsDiskArray[$docDiskYear . '/' . $docDiskMonth . '/' . $docDiskDay][] = $file;
                         }
                     }
                 }
             }
             $docsDbData = $this->getDocumentsData();
             /** @var \DDD\Domain\Document\Document $docDb */
             foreach ($docsDbData as $docDb) {
                 $dateFolder = date('Y/m/j', strtotime($docDb->getCreatedDate()));
                 $attachment = $documentUploadsPath . $dateFolder . '/' . $docDb->getAttachment();
                 if (!empty($docDb->getAttachment()) and $docDb->getAttachment() !== null) {
                     if (!is_file($attachment)) {
                         $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_DOCUMENTS . '.apartment_id: ' . $docDb->getID() . PHP_EOL . 'attachment: ' . PHP_EOL . $attachment]);
                     } else {
                         $filename = $docDb->getAttachment();
                         foreach ($docsDiskArray[$dateFolder] as $docFileKey => $docFile) {
                             if ($docFile === $filename) {
                                 unset($docsDiskArray[$dateFolder][$docFileKey]);
                             }
                         }
                     }
                 }
             }
             foreach ($docsDiskArray as $dateFolder => $docFiles) {
                 foreach ($docFiles as $key => $docFile) {
                     $unusedDocumentFile = $documentUploadsPath . $dateFolder . '/' . $docFile;
                     $unusedFiles[] = $unusedDocumentFile;
                     if (is_dir($unusedDocumentFile)) {
                         $table->appendRow([$this->runCounter(), 'type: Apartment Documents' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedDocumentFile, 'x']);
                     } else {
                         $table->appendRow([$this->runCounter(), 'type: Apartment Documents' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedDocumentFile, 'x']);
                     }
                 }
             }
         }
     }
     /**
      * Apartment Maps
      */
     if ($this->onlyBuildingMaps or $this->withOutParams) {
         $buildingImagesPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_BUILDING;
         if (!is_readable($buildingImagesPath)) {
             echo "Folder does not exist: " . $buildingImagesPath . PHP_EOL . PHP_EOL;
         } else {
             $buildingDiskData = array_diff(scandir($buildingImagesPath), ['.', '..']);
             $mapsDiskArray = [];
             foreach ($buildingDiskData as $buildingId) {
                 if (is_dir($buildingImagesPath . $buildingId . '/map')) {
                     $thisFilesList = array_diff(scandir($buildingImagesPath . $buildingId . '/map'), ['.', '..']);
                     if (count($thisFilesList)) {
                         foreach ($thisFilesList as $file) {
                             $mapsDiskArray[$buildingId][] = $file;
                         }
                     }
                 }
             }
             $mapsDbData = $this->getBuildingsMapsData();
             foreach ($mapsDbData as $mapsDb) {
                 $file = substr($buildingImagesPath, 0, -1) . '/' . $mapsDb['building_id'] . '/map/' . $mapsDb['map_attachment'];
                 if (!empty($mapsDb['map_attachment']) && $mapsDb['map_attachment'] !== null and !is_file($file)) {
                     $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_BUILDING_DETAILS . '.id: ' . $mapsDb['id'] . PHP_EOL . DbTables::TBL_BUILDING_DETAILS . '.apartment_group_id: ' . $mapsDb['building_id'] . PHP_EOL . 'img: ' . PHP_EOL . $file]);
                 } elseif (!empty($mapsDb['map_attachment']) and $mapsDb['map_attachment'] !== null) {
                     foreach ($mapsDiskArray[$mapsDb['building_id']] as $mapsFileKey => $mapsFile) {
                         if ($mapsFile == $mapsDb['map_attachment']) {
                             unset($mapsDiskArray[$mapsDb['building_id']][$mapsFileKey]);
                         }
                     }
                 }
             }
             foreach ($mapsDiskArray as $folder => $mapsDisk) {
                 foreach ($mapsDisk as $mapsDiskFile) {
                     $unusedMapsFile = $buildingImagesPath . $folder . '/map/' . $mapsDiskFile;
                     $unusedFiles[] = $unusedMapsFile;
                     if (is_dir($unusedMapsFile)) {
                         $table->appendRow([$this->runCounter(), 'type: Building Maps' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedMapsFile, 'x']);
                     } else {
                         $table->appendRow([$this->runCounter(), 'type: Building Maps' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedMapsFile, 'x']);
                     }
                 }
             }
         }
     }
     /**
      * Apartment Maps
      */
     if ($this->onlyOfficeMaps or $this->withOutParams) {
         $officeImagesPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_OFFICE;
         if (!is_readable($officeImagesPath)) {
             echo "Folder does not exist: " . $officeImagesPath . PHP_EOL . PHP_EOL;
         } else {
             $officeDiskData = array_diff(scandir($officeImagesPath), ['.', '..']);
             $mapsDiskArray = [];
             foreach ($officeDiskData as $officeId) {
                 if (is_dir($officeImagesPath . $officeId)) {
                     $thisFilesList = array_diff(scandir($officeImagesPath . $officeId), ['.', '..']);
                     if (count($thisFilesList)) {
                         foreach ($thisFilesList as $file) {
                             $mapsDiskArray[$officeId][] = $file;
                         }
                     }
                 }
             }
             $mapsDbData = $this->getOfficeMapsData();
             foreach ($mapsDbData as $mapsDb) {
                 $file = substr($officeImagesPath, 0, -1) . '/' . $mapsDb->getId() . '/map/' . $mapsDb->getMapAttachment();
                 if (!empty($mapsDb->getMapAttachment()) && $mapsDb->getMapAttachment() !== null and !is_file($file)) {
                     $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_OFFICES . '.id: ' . $mapsDb->getId() . PHP_EOL . 'img: ' . PHP_EOL . $file]);
                 } elseif (!empty($mapsDb->getMapAttachment()) and $mapsDb->getMapAttachment() !== null) {
                     foreach ($mapsDiskArray[$mapsDb->getId()] as $mapsFileKey => $mapsFile) {
                         if ($mapsFile == $mapsDb->getMapAttachment()) {
                             unset($mapsDiskArray[$mapsDb->getId()][$mapsFileKey]);
                         }
                     }
                 }
             }
             foreach ($mapsDiskArray as $folder => $mapsDisk) {
                 foreach ($mapsDisk as $mapsDiskFile) {
                     $unusedMapsFile = $officeImagesPath . $folder . '/map/' . $mapsDiskFile;
                     $unusedFiles[] = $unusedMapsFile;
                     if (is_dir($unusedMapsFile)) {
                         $table->appendRow([$this->runCounter(), 'type: Office Maps' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedMapsFile, 'x']);
                     } else {
                         $table->appendRow([$this->runCounter(), 'type: Office Maps' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedMapsFile, 'x']);
                     }
                 }
             }
         }
     }
     /**
      * Blog
      */
     if ($this->onlyBlogImages or $this->withOutParams) {
         $blogImagesPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_BLOG_PATH;
         if (!is_readable($blogImagesPath)) {
             echo "Folder does not exist: " . $blogImagesPath . PHP_EOL . PHP_EOL;
         } else {
             $blogsDiskData = array_diff(scandir($blogImagesPath), ['.', '..']);
             $blogsDiskArray = [];
             foreach ($blogsDiskData as $blogDisk) {
                 $thisFilesList = array_diff(scandir($blogImagesPath . $blogDisk), ['.', '..']);
                 foreach ($thisFilesList as $file) {
                     $blogsDiskArray[$blogDisk][] = $file;
                 }
             }
             $blogsDbData = $this->getBlogsData();
             foreach ($blogsDbData as $blogDb) {
                 $img = substr(DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT, 0, -1) . $blogDb->getImg();
                 if (!empty($blogDb->getImg()) and $blogDb->getImg() !== null and !is_file($img)) {
                     $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_BLOG_POSTS . '.id: ' . $blogDb->getId() . PHP_EOL . 'img: ' . PHP_EOL . $img]);
                 } elseif (!empty($blogDb->getImg()) and $blogDb->getImg() !== null) {
                     $filename = explode('_', explode('/', $blogDb->getImg())[3])[0];
                     foreach ($blogsDiskArray[$blogDb->getId()] as $blogFileKey => $blogFile) {
                         if (strstr($blogFile, $filename)) {
                             unset($blogsDiskArray[$blogDb->getId()][$blogFileKey]);
                         }
                     }
                 }
             }
             foreach ($blogsDiskArray as $folder => $blogDisk) {
                 foreach ($blogDisk as $blogDiskFiles) {
                     $unusedBlogFile = $blogImagesPath . $folder . '/' . $blogDiskFiles;
                     $unusedFiles[] = $unusedBlogFile;
                     if (is_dir($unusedBlogFile)) {
                         $table->appendRow([$this->runCounter(), 'type: Blogs' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedBlogFile, 'x']);
                     } else {
                         $table->appendRow([$this->runCounter(), 'type: Blogs' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedBlogFile, 'x']);
                     }
                 }
             }
         }
     }
     /**
      * Users Documents
      */
     if ($this->onlyUsersDocuments or $this->withOutParams) {
         $userUploadsPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_USER_DOCUMENTS;
         if (!is_readable($userUploadsPath)) {
             echo "Folder does not exist: " . $userUploadsPath . PHP_EOL . PHP_EOL;
         } else {
             $usersDocsDiskData = array_diff(scandir($userUploadsPath), ['.', '..']);
             $usersDocsDiskArray = [];
             foreach ($usersDocsDiskData as $userDocDisk) {
                 $thisFilesList = array_diff(scandir($userUploadsPath . $userDocDisk), ['.', '..']);
                 foreach ($thisFilesList as $file) {
                     $usersDocsDiskArray[$userDocDisk][] = $file;
                 }
             }
             $usersDocsDbData = $this->getUsersDocumentsData();
             foreach ($usersDocsDbData as $userDocDb) {
                 $attachment = $userUploadsPath . $userDocDb->getUserId() . '/' . $userDocDb->getAttachment();
                 if (!empty($userDocDb->getAttachment()) and $userDocDb->getAttachment() !== null and !is_file($attachment)) {
                     $table->appendRow([$this->runCounter(), 'x', 'ga_bo_user_documents.id: ' . $userDocDb->getId() . PHP_EOL . 'attachment: ' . PHP_EOL . $attachment]);
                 } elseif (!empty($userDocDb->getAttachment()) and $userDocDb->getAttachment() !== null) {
                     $filename = $userDocDb->getAttachment();
                     foreach ($usersDocsDiskArray[$userDocDb->getUserId()] as $userDocFileKey => $userDocFile) {
                         if ($userDocFile === $filename) {
                             unset($usersDocsDiskArray[$userDocDb->getUserId()][$userDocFileKey]);
                         }
                     }
                 }
             }
             foreach ($usersDocsDiskArray as $folder => $userDocDisk) {
                 foreach ($userDocDisk as $userDocDiskFiles) {
                     $unusedUserDocumentsFile = $userUploadsPath . $folder . '/' . $userDocDiskFiles;
                     $unusedFiles[] = $unusedUserDocumentsFile;
                     if (is_dir($unusedUserDocumentsFile)) {
                         $table->appendRow([$this->runCounter(), 'type: User Documents' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedUserDocumentsFile, 'x']);
                     } else {
                         $table->appendRow([$this->runCounter(), 'type: User Documents' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedUserDocumentsFile, 'x']);
                     }
                 }
             }
         }
     }
     /**
      * Jobs Documents
      */
     if ($this->onlyJobsDocuments or $this->withOutParams) {
         $applicantUploadsPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_HR_APPLICANT_DOCUMENTS;
         if (!is_readable($applicantUploadsPath)) {
             echo "Folder does not exist: " . $applicantUploadsPath . PHP_EOL . PHP_EOL;
         } else {
             $jobsDocsDiskData = array_diff(scandir($applicantUploadsPath), ['.', '..']);
             $jobsDocsDiskArray = [];
             foreach ($jobsDocsDiskData as $jobDocDiskYear) {
                 $yearFilesList = array_diff(scandir($applicantUploadsPath . $jobDocDiskYear), ['.', '..']);
                 foreach ($yearFilesList as $jobDocDiskMonth) {
                     $monthFilesList = array_diff(scandir($applicantUploadsPath . $jobDocDiskYear . '/' . $jobDocDiskMonth), ['.', '..']);
                     foreach ($monthFilesList as $file) {
                         $jobsDocsDiskArray[$jobDocDiskYear][$jobDocDiskMonth][] = $file;
                     }
                 }
             }
             $jobsDocsDbData = $this->getJobsDocumentsData();
             foreach ($jobsDocsDbData as $jobDocDb) {
                 $attachmentDate = explode('-', $jobDocDb->getDateApplied());
                 $attachment = $applicantUploadsPath . $attachmentDate[0] . '/' . $attachmentDate[1] . '/' . $jobDocDb->getCvFileName();
                 if (!empty($jobDocDb->getCvFileName()) and $jobDocDb->getCvFileName() !== null and !is_file($attachment)) {
                     $table->appendRow([$this->runCounter(), 'x', 'ga_hr_applicants.id: ' . $jobDocDb->getId() . PHP_EOL . 'attachment: ' . PHP_EOL . $attachment]);
                 } elseif (!empty($jobDocDb->getCvFileName()) and $jobDocDb->getCvFileName() !== null) {
                     $filename = $jobDocDb->getCvFileName();
                     foreach ($jobsDocsDiskArray[$attachmentDate[0]][$attachmentDate[1]] as $jobDocFileKey => $jobDocFile) {
                         if ($jobDocFile === $filename) {
                             unset($jobsDocsDiskArray[$attachmentDate[0]][$attachmentDate[1]][$jobDocFileKey]);
                         }
                     }
                 }
             }
             foreach ($jobsDocsDiskArray as $year => $monthFiles) {
                 foreach ($monthFiles as $month => $jobDocDiskFiles) {
                     foreach ($jobDocDiskFiles as $fileKey => $jobDocDiskFile) {
                         $unusedJobDocumentFile = $applicantUploadsPath . $year . '/' . $month . '/' . $jobDocDiskFile;
                         $unusedFiles[] = $unusedJobDocumentFile;
                         if (is_dir($unusedJobDocumentFile)) {
                             $table->appendRow([$this->runCounter(), 'type: Applicant Documents' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedJobDocumentFile, 'x']);
                         } else {
                             $table->appendRow([$this->runCounter(), 'type: Applicant Documents' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedJobDocumentFile, 'x']);
                         }
                     }
                 }
             }
         }
     }
     /**
      * Booking attached documents
      */
     if ($this->onlyBookingDocuments || $this->withOutParams) {
         $bookingDocFolder = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_BOOKING_DOCUMENTS;
         if (!is_readable($bookingDocFolder)) {
             echo "Folder does not exist: " . $bookingDocFolder . PHP_EOL . PHP_EOL;
         } else {
             $bookingDocsDiskData = array_diff(scandir($bookingDocFolder), ['.', '..']);
             $bookingDocsDiskArray = [];
             foreach ($bookingDocsDiskData as $bookingDocDiskYear) {
                 $yearFilesList = array_diff(scandir($bookingDocFolder . $bookingDocDiskYear), ['.', '..']);
                 foreach ($yearFilesList as $bookingDocDiskMonth) {
                     $monthFilesList = array_diff(scandir($bookingDocFolder . $bookingDocDiskYear . '/' . $bookingDocDiskMonth), ['.', '..']);
                     foreach ($monthFilesList as $BookingsList) {
                         $bookingsList = array_diff(scandir($bookingDocFolder . $bookingDocDiskYear . '/' . $bookingDocDiskMonth . '/' . $BookingsList), ['.', '..']);
                         foreach ($bookingsList as $bookingDocsList) {
                             $docList = array_diff(scandir($bookingDocFolder . $bookingDocDiskYear . '/' . $bookingDocDiskMonth . '/' . $BookingsList . '/' . $bookingDocsList), ['.', '..']);
                             foreach ($docList as $file) {
                                 $bookingDocsDiskArray[$bookingDocDiskYear][$bookingDocDiskMonth][$BookingsList][$bookingDocsList][] = $file;
                             }
                         }
                     }
                 }
             }
             $bookingsDocsDbData = $this->getReservationAttachmentsData();
             foreach ($bookingsDocsDbData as $bookingDocDb) {
                 $createdDate = $bookingDocDb->getCreatedDate();
                 $year = date('Y', strtotime($createdDate));
                 $month = date('m', strtotime($createdDate));
                 $attachment = $bookingDocFolder . $year . '/' . $month . '/' . $bookingDocDb->getReservationId() . '/' . $bookingDocDb->getDocId() . '/' . $bookingDocDb->getAttachment();
                 if (!empty($bookingDocDb->getAttachment()) && $bookingDocDb->getAttachment() !== null && !is_file($attachment)) {
                     $table->appendRow([$this->runCounter(), 'x', 'ga_reservation_attachment_items.id: ' . $bookingDocDb->getId() . PHP_EOL . 'attachment: ' . PHP_EOL . $attachment]);
                 } elseif (!empty($bookingDocDb->getAttachment()) && $bookingDocDb->getAttachment() !== null) {
                     $filename = $bookingDocDb->getAttachment();
                     foreach ($bookingDocsDiskArray[$year][$month][$bookingDocDb->getReservationId()] as $bookingDocFileKey => $bookingDocFile) {
                         foreach ($bookingDocFile as $docFiles => $bookDocFile) {
                             if ($bookDocFile === $filename) {
                                 unset($bookingDocsDiskArray[$year][$month][$bookingDocDb->getReservationId()][$bookingDocFileKey][$docFiles]);
                             }
                         }
                     }
                 }
             }
             foreach ($bookingDocsDiskArray as $year => $monthFiles) {
                 foreach ($monthFiles as $month => $booksId) {
                     foreach ($booksId as $bookId => $docsId) {
                         foreach ($docsId as $bookingDocId => $bookingFileList) {
                             foreach ($bookingFileList as $bookingFileKey => $bookingDiskFile) {
                                 $unusedBookingDocFile = $bookingDocFolder . $year . '/' . $month . '/' . $bookId . '/' . $bookingDocId . '/' . $bookingDiskFile;
                                 $unusedFiles[] = $unusedBookingDocFile;
                                 if (is_dir($unusedBookingDocFile)) {
                                     $table->appendRow([$this->runCounter(), 'type: Booking Documents' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedBookingDocFile, 'x']);
                                 } else {
                                     $table->appendRow([$this->runCounter(), 'type: Booking Documents' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedBookingDocFile, 'x']);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     /**
      * Money Account attached documents
      */
     if ($this->onlyMoneyAccountDocuments || $this->withOutParams) {
         $moneyAccountDocFolder = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_MONEY_ACCOUNT_DOCUMENTS;
         if (!is_readable($moneyAccountDocFolder)) {
             echo "Folder does not exist: " . $moneyAccountDocFolder . PHP_EOL . PHP_EOL;
         } else {
             $moneyAccountDocsDiskData = array_diff(scandir($moneyAccountDocFolder), ['.', '..']);
             $moneyAccountDocsDiskArray = [];
             foreach ($moneyAccountDocsDiskData as $moneyAccountDocDiskYear) {
                 $yearFilesList = array_diff(scandir($moneyAccountDocFolder . $moneyAccountDocDiskYear), ['.', '..']);
                 foreach ($yearFilesList as $moneyAccountDocDiskMonth) {
                     $monthFilesList = array_diff(scandir($moneyAccountDocFolder . $moneyAccountDocDiskYear . '/' . $moneyAccountDocDiskMonth), ['.', '..']);
                     foreach ($monthFilesList as $MoneyAccountsList) {
                         $moneyAccountsList = array_diff(scandir($moneyAccountDocFolder . $moneyAccountDocDiskYear . '/' . $moneyAccountDocDiskMonth . '/' . $MoneyAccountsList), ['.', '..']);
                         foreach ($moneyAccountsList as $moneyAccountsDocsList) {
                             $docList = array_diff(scandir($moneyAccountDocFolder . $moneyAccountDocDiskYear . '/' . $moneyAccountDocDiskMonth . '/' . $MoneyAccountsList . '/' . $moneyAccountsDocsList), ['.', '..']);
                             foreach ($docList as $file) {
                                 $moneyAccountDocsDiskArray[$moneyAccountDocDiskYear][$moneyAccountDocDiskMonth][$MoneyAccountsList][$moneyAccountsDocsList][] = $file;
                             }
                         }
                     }
                 }
             }
             $moneyAccountsDocsDbData = $this->getMoneyAccountAttachmentsData();
             foreach ($moneyAccountsDocsDbData as $moneyAccountDocDb) {
                 $createdDate = $moneyAccountDocDb->getCreatedDate();
                 $year = date('Y', strtotime($createdDate));
                 $month = date('m', strtotime($createdDate));
                 $attachment = $moneyAccountDocFolder . $year . '/' . $month . '/' . $moneyAccountDocDb->getMoneyAccountId() . '/' . $moneyAccountDocDb->getDocId() . '/' . $moneyAccountDocDb->getAttachment();
                 if (!empty($moneyAccountDocDb->getAttachment()) && $moneyAccountDocDb->getAttachment() !== null && !is_file($attachment)) {
                     $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_MONEY_ACCOUNT_ATTACHMENT_ITEMS . '.id: ' . $moneyAccountDocDb->getId() . PHP_EOL . 'attachment: ' . PHP_EOL . $attachment]);
                 } elseif (!empty($moneyAccountDocDb->getAttachment()) && $moneyAccountDocDb->getAttachment() !== null) {
                     $filename = $moneyAccountDocDb->getAttachment();
                     foreach ($moneyAccountDocsDiskArray[$year][$month][$moneyAccountDocDb->getMoneyAccountId()] as $moneyAccountDocFileKey => $moneyAccountDocFile) {
                         foreach ($moneyAccountDocFile as $docFiles => $monAccDocFile) {
                             if ($monAccDocFile === $filename) {
                                 unset($moneyAccountDocsDiskArray[$year][$month][$moneyAccountDocDb->getMoneyAccountId()][$moneyAccountDocFileKey][$docFiles]);
                             }
                         }
                     }
                 }
             }
             foreach ($moneyAccountDocsDiskArray as $year => $monthFiles) {
                 foreach ($monthFiles as $month => $monacsId) {
                     foreach ($monacsId as $monacId => $docsId) {
                         foreach ($docsId as $moneyAccountDocId => $moneyAccountFileList) {
                             foreach ($moneyAccountFileList as $moneyAccountFileKey => $moneyAccountDiskFile) {
                                 $unusedMoneyAccountDocFile = $moneyAccountDocFolder . $year . '/' . $month . '/' . $monacId . '/' . $moneyAccountDocId . '/' . $moneyAccountDiskFile;
                                 $unusedFiles[] = $unusedMoneyAccountDocFile;
                                 if (is_dir($unusedMoneyAccountDocFile)) {
                                     $table->appendRow([$this->runCounter(), 'type: Money Account Documents' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedMoneyAccountDocFile, 'x']);
                                 } else {
                                     $table->appendRow([$this->runCounter(), 'type: Money Account Documents' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedMoneyAccountDocFile, 'x']);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     /**
      * Task attachments
      */
     if ($this->onlyTaskAttachments || $this->withOutParams) {
         $taskAttachmentsFolder = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_TASK_ATTACHMENTS;
         if (!is_readable($taskAttachmentsFolder)) {
             echo "Folder does not exist: " . $taskAttachmentsFolder . PHP_EOL . PHP_EOL;
         } else {
             $taskAttachmentsDiskData = array_diff(scandir($taskAttachmentsFolder), ['.', '..']);
             $taskAttachmentsDiskArray = [];
             foreach ($taskAttachmentsDiskData as $year) {
                 $monthList = array_diff(scandir($taskAttachmentsFolder . $year), ['.', '..']);
                 foreach ($monthList as $month) {
                     $dayList = array_diff(scandir($taskAttachmentsFolder . $year . '/' . $month), ['.', '..']);
                     foreach ($dayList as $day) {
                         $idList = array_diff(scandir($taskAttachmentsFolder . $year . '/' . $month . '/' . $day), ['.', '..']);
                         foreach ($idList as $id) {
                             $taskAttachmentsList = array_diff(scandir($taskAttachmentsFolder . $year . '/' . $month . '/' . $day . '/' . $id), ['.', '..']);
                             foreach ($taskAttachmentsList as $file) {
                                 $taskAttachmentsDiskArray[$year][$month][$day][$id][] = $file;
                             }
                         }
                     }
                 }
             }
             $taskAttachmentsDbData = $this->getTaskAttachmentsData();
             foreach ($taskAttachmentsDbData as $taskAttachmentDb) {
                 $attachmentDate = explode('/', $taskAttachmentDb->getPath());
                 $attachment = $taskAttachmentsFolder . $taskAttachmentDb->getPath() . '/' . $taskAttachmentDb->getTaskId() . '/' . $taskAttachmentDb->getFile();
                 if (!empty($taskAttachmentDb->getFile()) and !is_file($attachment)) {
                     $table->appendRow([$this->runCounter(), 'x', 'ga_task_attachments.id: ' . $taskAttachmentDb->getId() . PHP_EOL . 'attachment: ' . PHP_EOL . $attachment]);
                 } elseif (!empty($taskAttachmentDb->getFile())) {
                     $filename = $taskAttachmentDb->getFile();
                     $key = array_search($filename, $taskAttachmentsDiskArray[$attachmentDate[0]][$attachmentDate[1]][$attachmentDate[2]][$taskAttachmentDb->getTaskId()]);
                     if ($key !== false) {
                         unset($taskAttachmentsDiskArray[$attachmentDate[0]][$attachmentDate[1]][$attachmentDate[2]][$taskAttachmentDb->getTaskId()][$key]);
                     }
                 }
             }
             if (count($taskAttachmentsDiskArray)) {
                 foreach ($taskAttachmentsDiskArray as $year => $monthFiles) {
                     foreach ($monthFiles as $month => $dayFiles) {
                         foreach ($dayFiles as $day => $idFiles) {
                             foreach ($idFiles as $taskId => $files) {
                                 foreach ($files as $file) {
                                     $unusedTaskAttachmentFile = $taskAttachmentsFolder . $year . '/' . $month . '/' . $day . '/' . $taskId . '/' . $file;
                                     $unusedFiles[] = $unusedTaskAttachmentFile;
                                     if (is_dir($unusedTaskAttachmentFile)) {
                                         $table->appendRow([$this->runCounter(), 'type: Task Attachments' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedTaskAttachmentFile, 'x']);
                                     } else {
                                         $table->appendRow([$this->runCounter(), 'type: Task Attachments' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedTaskAttachmentFile, 'x']);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     /**
      * Parking attachments
      */
     if ($this->onlyParkingAttachments || $this->withOutParams) {
         $parkingAttachmentsFolder = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_PARKING_ATTACHMENTS;
         if (!is_readable($parkingAttachmentsFolder)) {
             echo "Folder does not exist: " . $parkingAttachmentsFolder . PHP_EOL . PHP_EOL;
         } else {
             $parkingAttachmentsDiskData = array_diff(scandir($parkingAttachmentsFolder), ['.', '..']);
             $parkingAttachmentsDiskArray = [];
             foreach ($parkingAttachmentsDiskData as $id) {
                 $parkingAttachmentsList = array_diff(scandir($parkingAttachmentsFolder . $id), ['.', '..']);
                 foreach ($parkingAttachmentsList as $file) {
                     $parkingAttachmentsDiskArray[$id][] = $file;
                 }
             }
             $parkingAttachmentsDbData = $this->getParkingAttachmentsData();
             foreach ($parkingAttachmentsDbData as $parkingAttachmentDb) {
                 $attachment = $parkingAttachmentsFolder . '/' . $parkingAttachmentDb->getId() . '/' . $parkingAttachmentDb->getParkingPermit();
                 if (!empty($parkingAttachmentDb->getParkingPermit()) and !is_file($attachment)) {
                     $table->appendRow([$this->runCounter(), 'x', 'ga_parking_attachments.id: ' . $parkingAttachmentDb->getId() . PHP_EOL . 'attachment: ' . PHP_EOL . $attachment]);
                 } elseif (!empty($parkingAttachmentDb->getParkingPermit())) {
                     $filename = $parkingAttachmentDb->getParkingPermit();
                     $key = array_search($filename, $parkingAttachmentsDiskArray[$parkingAttachmentDb->getId()]);
                     if ($key !== false) {
                         unset($parkingAttachmentsDiskArray[$parkingAttachmentDb->getId()][$key]);
                     }
                 }
             }
             if (count($parkingAttachmentsDiskArray)) {
                 foreach ($parkingAttachmentsDiskArray as $parkingId => $files) {
                     foreach ($files as $file) {
                         $unusedParkingAttachmentFile = $parkingAttachmentsFolder . $parkingId . '/' . $file;
                         $unusedFiles[] = $unusedParkingAttachmentFile;
                         if (is_dir($unusedParkingAttachmentFile)) {
                             $table->appendRow([$this->runCounter(), 'type: Parking Attachments' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedParkingAttachmentFile, 'x']);
                         } else {
                             $table->appendRow([$this->runCounter(), 'type: Parking Attachments' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedParkingAttachmentFile, 'x']);
                         }
                     }
                 }
             }
         }
     }
     // Apartel Images
     if ($this->onlyApartelImages || $this->withOutParams) {
         $apartelImagesPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_APARTEL_BG_IMAGE;
         if (!is_readable($apartelImagesPath)) {
             echo "Folder does not exist: " . $apartelImagesPath . PHP_EOL . PHP_EOL;
         } else {
             $apartelImagesDiskData = array_diff(scandir($apartelImagesPath), ['.', '..']);
             $apartelImagesDiskArray = [];
             foreach ($apartelImagesDiskData as $apartelImageDisk) {
                 $thisFilesList = array_diff(scandir($apartelImagesPath . $apartelImageDisk), ['.', '..']);
                 foreach ($thisFilesList as $file) {
                     $apartelImagesDiskArray[$apartelImageDisk][] = $file;
                 }
             }
             $apartelImagesDbData = $this->getApartelImagesData();
             foreach ($apartelImagesDbData as $apartelImageDb) {
                 /**
                  * @var \DDD\Domain\Apartel\Details\Details $apartelImageDb
                  */
                 $bgImage = $apartelImagesPath . $apartelImageDb->getApartelId() . '/' . $apartelImageDb->getBgImage();
                 if (!empty($apartelImageDb->getBgImage()) && $apartelImageDb->getBgImage() !== null && !is_file($bgImage)) {
                     $table->appendRow([$this->runCounter(), 'x', DbTables::TBL_APARTELS_DETAILS . '.id: ' . $apartelImageDb->getId() . PHP_EOL . 'apartel id: ' . $apartelImageDb->getApartelId() . PHP_EOL . 'cover_image: ' . PHP_EOL . $bgImage]);
                 } elseif (!empty($apartelImageDb->getBgImage()) && $apartelImageDb->getBgImage() !== null) {
                     $filename = explode('_', $apartelImageDb->getBgImage())[0];
                     foreach ($apartelImagesDiskArray[$apartelImageDb->getApartelId()] as $apartelFileKey => $apartelFile) {
                         if (strstr($apartelFile, $filename)) {
                             unset($apartelImagesDiskArray[$apartelImageDb->getApartelId()][$apartelFileKey]);
                         }
                     }
                 }
             }
             foreach ($apartelImagesDiskArray as $folder => $apartelDisk) {
                 foreach ($apartelDisk as $apartelDiskFiles) {
                     $unusedApartelFile = $apartelImagesPath . $folder . '/' . $apartelDiskFiles;
                     $unusedFiles[] = $unusedApartelFile;
                     if (is_dir($unusedApartelFile)) {
                         $table->appendRow([$this->runCounter(), 'type: Apartel Image' . PHP_EOL . '-=!=- UNKNOWN FOLDER -=!=- ' . PHP_EOL . $unusedApartelFile, 'x']);
                     } else {
                         $table->appendRow([$this->runCounter(), 'type: Apartel Image' . PHP_EOL . 'filename: ' . PHP_EOL . $unusedApartelFile, 'x']);
                     }
                 }
             }
         }
     }
     // Purchase Order
     if ($this->onlyPurchaseOrder || $this->withOutParams) {
         $this->matchAttachments($table, ['id' => 'id', 'date' => 'date', 'filename' => 'filename', 'dir' => '/ginosi/uploads/expense', 'type' => 'Purchase Order Attachment ', 'depth' => 4, 'sql' => '
                 select
                     ga_expense.id as id,
                     ga_expense.date_created as date,
                     ga_expense_attachments.filename
                 from ga_expense_attachments
                     left join ga_expense on ga_expense.id = ga_expense_attachments.expense_id
             ']);
     }
     // Purchase Order Items
     if ($this->onlyPurchaseOrderItems || $this->withOutParams) {
         $this->matchAttachments($table, ['id' => 'id', 'filename' => 'filename', 'dir' => '/ginosi/uploads/expense/items', 'type' => 'Purchase Order Item Attachment ', 'depth' => 5, 'sql' => '
                 select
                     filename
                 from ga_expense_item_attachments
                 where expense_id IS NOT NULL
             ']);
         $this->matchAttachments($table, ['id' => 'id', 'filename' => 'filename', 'dir' => '/ginosi/uploads/expense/items_tmp', 'type' => 'Purchase Order Temporary Items Attachment ', 'depth' => 1, 'sql' => '
                 select
                     filename
                 from ga_expense_item_attachments
                 where expense_id IS NULL
             ']);
     }
     echo PHP_EOL . 'Rendering table...' . PHP_EOL;
     sleep(1);
     echo $table;
     /**
      * REMOVE UNUSED FILES FROM DISK
      */
     if (count($unusedFiles) > 0 and $this->removeFromDisk) {
         echo PHP_EOL;
         echo "!!! WARNING !!!";
         if (Prompt\Confirm::prompt(PHP_EOL . 'Are you absolutely sure you want to permanently delete unused files from hard disk? You have already created backup copy of these files? [y/n]' . PHP_EOL, 'y', 'n')) {
             echo PHP_EOL;
             $secretWord = Prompt\Line::prompt('Please say the magic word and press [ENTER]: ', false, 30);
             echo PHP_EOL . PHP_EOL;
             if ($secretWord === 'please') {
                 echo "go go go..." . PHP_EOL;
                 foreach ($unusedFiles as $fileToRemove) {
                     if (is_writable($fileToRemove)) {
                         if (is_dir($fileToRemove)) {
                             $this->delTree($fileToRemove);
                         } else {
                             unlink($fileToRemove);
                         }
                         echo "Removed: " . $fileToRemove . PHP_EOL;
                     } else {
                         echo "Cannot remove file (permissions denied): " . $fileToRemove . PHP_EOL;
                     }
                 }
             } else {
                 echo "Wrong! Try again :P" . PHP_EOL;
             }
         } else {
             echo "You chose NO :(" . PHP_EOL;
         }
     }
     echo PHP_EOL . 'Reporting done!' . PHP_EOL . PHP_EOL;
 }
Ejemplo n.º 18
0
 /**
  * Write a customizable confirm prompt
  *
  * @param string $message
  * @param string $yes
  * @param string $no
  *
  * @return bool
  */
 public function writeConfirmPrompt($message, $yes, $no)
 {
     $this->writeLine();
     // write prompt badge
     $this->writeBadge('badge_pick', Color::RED);
     // output prompt
     $prompt = new Confirm($this->translator->translate($message), $this->translator->translate($yes), $this->translator->translate($no));
     $answer = $prompt->show();
     return $answer;
 }
Ejemplo n.º 19
0
 public function createAction()
 {
     $request = $this->getRequest();
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('This action can only be used from a console!');
     }
     try {
         $console = Console::getInstance();
     } catch (ConsoleException $e) {
         throw new \RuntimeException('This action can only be used from a console!');
     }
     $this->setValidatorService($this->getServiceLocator()->get('loslicense.validator'));
     $outputFile = $request->getParam('outputFile', null);
     $writer = new \LosLicense\Config\Writer\PhpArray();
     $writer->setUseBracketArraySyntax(true);
     $options = ['Trial', 'Personal', 'Standard'];
     $type = Select::prompt('License type?', $options, false, true);
     $valid_from = Line::prompt("\nValid from (Enter to not set one) YYYY-MM-DD HH:II:SS ? ", true, 20);
     $valid_until = Line::prompt("\nValid until (Enter to not set one) YYYY-MM-DD HH:II:SS ? ", true, 20);
     $customer = Line::prompt("\nCustomer? ", true, 100);
     $options = $this->getServiceLocator()->get('loslicense.options');
     $features = $options->getFeatures();
     $checked = Checkbox::prompt("\nFeatures? (Enter to finish) ", array_keys($features), true, true);
     $sign = false;
     if (Confirm::prompt("\nSign the license? [y/n] ", 'y', 'n')) {
         $sign = true;
     }
     if (Confirm::prompt("\nConfirm the license creation? [y/n] ", 'y', 'n')) {
         $config = new \Zend\Config\Config([], true);
         if ($type == 0) {
             $config->type = License::LICENSE_TRIAL;
             $license = new TrialLicense();
         } elseif ($type == 1) {
             $config->type = License::LICENSE_PERSONAL;
             $license = new PersonalLicense();
         } else {
             $config->type = License::LICENSE_STANDARD;
             $license = new StandardLicense();
         }
         $license->setType($config->type);
         if (!empty($valid_from)) {
             $from = new \DateTime($valid_from);
             $config->valid_from = $from->format('Y-m-d H:i:s');
             $license->setValidFrom($config->valid_from);
         }
         if (!empty($valid_until)) {
             $until = new \DateTime($valid_until);
             $config->valid_until = $until->format('Y-m-d H:i:s');
             $license->setValidUntil($config->valid_until);
         }
         if (!empty($customer)) {
             $config->customer = $customer;
             $license->setCustomer($config->customer);
         }
         if (!empty($checked)) {
             $config->features = [];
             $licenseFeatures = [];
             foreach ($features as $feature => $value) {
                 if (in_array($feature, $checked)) {
                     if ($value === null) {
                         $config->features->{$feature} = null;
                         $licenseFeatures[$feature] = null;
                     } else {
                         $config->features->{$feature} = $value;
                         $licenseFeatures[$feature] = $value;
                     }
                 }
             }
             $license->setFeatures($licenseFeatures);
         }
         if ($sign) {
             $signature = $this->getValidatorService()->signLicense($license);
             $config->signature = $signature;
         }
         if ($outputFile) {
             $writer->toFile($outputFile, $config);
         } else {
             echo $writer->toString($config);
         }
         $console->writeLine("License created", Color::GREEN);
     }
 }
Ejemplo n.º 20
0
$files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/../../../vendor/autoload.php'];
foreach ($files as $file) {
    if (file_exists($file)) {
        $loader = (require $file);
        break;
    }
}
if (!isset($loader)) {
    throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?');
}
$filePersister = new File(getcwd());
$gistPersister = new Gist(new Client());
$console = Console::getInstance();
$logo = new Logo();
$help = new Help();
$goodbye = new Goodbye();
$logo->draw($console);
$report = $help->help($console);
$file = $filePersister->persist($report);
$console->writeLine('The information has been saved to', ColorInterface::GREEN);
$console->writeLine(realpath($file), ColorInterface::BLACK, ColorInterface::CYAN);
$console->write('May I upload this information on https://gist.github.com/ ?', ColorInterface::CYAN);
$console->writeLine('[y/n]', ColorInterface::GREEN);
$prompt = new Confirm('');
$prompt->setConsole($console);
if ($prompt->show()) {
    $gistUri = $gistPersister->persist($report);
    $console->writeLine('The information was uploaded to', ColorInterface::GREEN);
    $console->writeLine($gistUri, ColorInterface::BLACK, ColorInterface::CYAN);
}
$goodbye->draw($console);