Exemple #1
0
 /**
  * Process an import request for a Byte registrant.
  *
  * @param Registrant $registrant
  * @param QuestionHelper $questionHelper
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function processByteRegistrantImportRequest(Registrant $registrant, QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output)
 {
     $client = $this->getByteClient();
     $output->writeln("Selected registrant <comment>{$registrant->getName()}</comment>");
     $domains = $client->getDomains($registrant);
     $domain = current($domains);
     if (count($domains) > 1) {
         $domain = $questionHelper->ask($input, $output, new ChoiceQuestion('Database domain: ' . "<comment>[{$domain}]</comment> ", $domains));
     }
     $output->writeln("Requesting database list for <comment>{$domain}</comment>. . .");
     $databases = $client->getDatabases($domain);
     if (empty($databases)) {
         throw new \RuntimeException("Could not fetch databases for domain: {$domain}");
     }
     $database = current($databases);
     if (count($databases) > 1) {
         // Let the user select a database.
         $database = $questionHelper->ask($input, $output, new ChoiceQuestion('Which database do you prefer? ' . "[<comment>{$database}</comment>]", $databases, $database));
     }
     $output->writeln("Fetching backup list for <comment>{$database}</comment>. . .");
     $backups = $client->getDatabaseBackups($domain, $database);
     $maximumBackups = 20;
     $numBackups = count($backups);
     if ($numBackups > $maximumBackups) {
         $output->writeln("Found <error>{$numBackups}</error>. Only using the first " . "<comment>{$maximumBackups}</comment>");
     }
     // Put a limit of on the backup list.
     $backups = array_slice($backups, 0, $maximumBackups);
     if (empty($backups)) {
         throw new \RuntimeException("Could not fetch database backup list for: {$database}");
     }
     /** @var DatabaseBackup $backup */
     $backup = current($backups);
     if (count($backups) > 1) {
         $backupOptions = array_map(function (DatabaseBackup $backup) {
             $size = (int) round($backup->getSize() / pow(1024, 2));
             return $backup->getDate()->format('D j M Y H:i') . " <comment>{$size} MB</comment>";
         }, $backups);
         $backupQuestion = new ChoiceQuestion('Which backup would you like to use? ', $backupOptions);
         $selectedBackup = $questionHelper->ask($input, $output, $backupQuestion);
         $backupIndex = array_search($selectedBackup, $backupOptions);
         if (!array_key_exists($backupIndex, $backups)) {
             throw new \RuntimeException('Offset does not exist in the list of available backups.');
         }
         $backup = $backups[$backupIndex];
     }
     $archive = $backup->getTempFileName();
     if (file_exists($archive) && filesize($archive) === $backup->getSize()) {
         $output->writeln("Using existing file: <comment>{$archive}</comment>");
     } else {
         $output->writeln("Downloading <comment>{$backup->getFileName()}</comment>. . .");
         if (!$client->downloadBackup($backup, $output)) {
             throw new \RuntimeException("Failed to download {$backup->getTempFileName()}");
         }
     }
     $archiveFiles = $client->listBackupFiles($backup);
     if (count($archiveFiles) !== 1) {
         throw new \RuntimeException("Could not determine SQL dump file in {$archive}");
     }
     $importFile = current($archiveFiles);
     $output->writeln("Identified SQL dump in archive: <comment>{$importFile}</comment>");
     $output->writeln("Extracting archive <comment>{$archive}</comment>. . .");
     $client->extractBackup($backup);
     if ($input->getOption('skip-data-stripping') !== true) {
         $this->cleanTables($importFile, ['aoe_profiler_run', 'core_session', 'log_url', 'log_url_info', 'log_visitor', 'log_visitor_info', 'log_visitor_online', 'report_event', 'report_compared_product_index', 'report_viewed_product_index', 'report_viewed_product_aggregated_daily', 'report_viewed_product_aggregated_monthly', 'report_viewed_product_aggregated_yearly', 'dataflow_batch', 'dataflow_batch_export', 'dataflow_batch_import', 'dataflow_import_data', 'dataflow_session', 'importexport_importdata', 'sales_order_aggregated_created', 'sales_order_aggregated_updated', 'sales_order_tax', 'sales_order_tax_item', 'sales_flat_creditmemo', 'sales_flat_creditmemo_comment', 'sales_flat_creditmemo_grid', 'sales_flat_creditmemo_item', 'sales_flat_invoice', 'sales_flat_invoice_comment', 'sales_flat_invoice_grid', 'sales_flat_invoice_item', 'sales_flat_order', 'sales_flat_order_address', 'sales_flat_order_grid', 'sales_flat_order_item', 'sales_flat_order_payment', 'sales_flat_order_status_history', 'sales_flat_quote', 'sales_flat_quote_address', 'sales_flat_quote_address_item', 'sales_flat_quote_item', 'sales_flat_quote_item_option', 'sales_flat_quote_payment', 'sales_flat_quote_shipment_rate', 'sales_flat_shipment', 'sales_flat_shipment_comment', 'sales_flat_shipment_grid', 'sales_flat_shipment_item', 'sales_flat_shipment_track', 'sales_recurring_profile', 'sales_recurring_profile_order', 'sales_refunded_aggregated', 'sales_refunded_aggregated_order', 'sales_payment_transaction', 'sales_bestsellers_aggregated_daily', 'sales_bestsellers_aggregated_monthly', 'sales_bestsellers_aggregated_yearly', 'customer_address_entity', 'customer_address_entity_datetime', 'customer_address_entity_decimal', 'customer_address_entity_int', 'customer_address_entity_text', 'customer_address_entity_varchar', 'customer_entity', 'customer_entity_datetime', 'customer_entity_decimal', 'customer_entity_int', 'customer_entity_text', 'customer_entity_varchar', 'wishlist', 'wishlist_item', 'wishlist_item_option', 'newsletter_problem', 'newsletter_queue', 'newsletter_queue_link', 'newsletter_queue_store_link', 'newsletter_subscriber', 'newsletter_template'], $output);
     }
     $this->rewriteDatabaseDefiner($importFile, $output);
     $this->importFile($importFile, $output);
     $output->writeln("Removing temporary dump file <comment>{$importFile}</comment>");
     unlink($importFile);
 }
 /**
  * Get a list of domains for the supplied registrant.
  *
  * @param Registrant $registrant
  * @return array
  */
 public function getDomains(Registrant $registrant)
 {
     $response = $this->getClient()->post('protected/overzicht/domains.cgi', ['form_params' => ['json' => json_encode(['regid' => $registrant->getId()])]]);
     preg_match_all('/\\<td\\>\\<a[^\\>]+\\>([^\\>]+)\\<\\/a\\>\\<\\/td\\>/', $response->getBody()->getContents(), $matches);
     $rv = array();
     if (!empty($matches[1])) {
         $rv = $matches[1];
     }
     return $rv;
 }