/** * @param String $env Name of the environment, f.i. 'development' or 'production'. */ public function distribute($env, $assetList, $assetCount) { $this->_validateEnvironment($env); $ini = new Garp_Config_Ini(APPLICATION_PATH . '/configs/application.ini', $env); if ($ini->cdn->readonly) { throw new Garp_File_Exception(Garp_File::EXCEPTION_CDN_READONLY); } if (!$assetCount || $ini->cdn->type !== 's3') { return; } Garp_Cli::lineOut(ucfirst($env)); $progressBar = Garp_Cli_Ui_ProgressBar::getInstance(); $progressBar->init($assetCount); $firstFilename = basename($assetList[0]); $fileOrFiles = $this->_printFileOrFiles($assetCount); $progressBar->display("Processing {$firstFilename}. {$assetCount} {$fileOrFiles} left."); $s3 = new Garp_File_Storage_S3($ini->cdn, dirname(current($assetList)), true); foreach ($assetList as $i => $asset) { $s3->setPath(dirname($asset)); $fileData = file_get_contents($this->_baseDir . $asset); $filename = basename($asset); if ($s3->store($filename, $fileData, true, false)) { $progressBar->advance(); $fileOrFiles = $this->_printFileOrFiles($assetCount - $progressBar->getProgress()); $progressBar->display("Processing {$filename}. %d {$fileOrFiles} left."); } else { $progressBar->displayError("Could not upload {$asset} to {$env}."); } } if ($progressBar->getProgress() === $assetCount) { $progressBar->display("√ Done"); } echo "\n\n"; }
protected function _storeZip(Garp_Service_PostcodeNl_Zipcode &$zip, $key, $overwrite) { $model = new Model_Location(); $select = $model->select()->where('zip = ? AND number IS NULL', $zip->zipcode); $existingRow = $model->fetchRow($select); if ($existingRow && $overwrite) { $model->delete('id = ' . $existingRow->id); } if (!$existingRow || $overwrite) { $this->_insertZip($zip, $model); } $this->_progress->advance(); $this->_progress->display('Importing zip codes', '%s left'); }
protected function _syncDb() { $mediator = new Garp_Content_Db_Mediator($this->_sourceEnv, $this->_targetEnv); $source = $mediator->getSource(); $target = $mediator->getTarget(); $this->_enableHighMemory(); $progress = Garp_Cli_Ui_ProgressBar::getInstance(); $progress->init(3); // 1. $progress->display("Backing up"); $target->backup(); $progress->advance(); // 2. $progress->display("Fetching data"); $dump = $source->fetchDump(); $progress->advance(); // 3. $progress->display("Injecting data"); $target->restore($dump); $progress->advance(); $progress->display("√ Database in sync"); }
protected function _getFeedbackInstance() { return $this->getInteractive() ? Garp_Cli_Ui_ProgressBar::getInstance() : Garp_Cli_Ui_BatchOutput::getInstance(); }
protected function _deleteNoLongerConfiguredColumn(Garp_Spawn_MySql_Column $targetColumn) { $source = $this->getSource(); $target = $this->getTarget(); $progress = Garp_Cli_Ui_ProgressBar::getInstance(); if ($source->columnExists($targetColumn->name)) { return; } if ($this->getFeedback()->isInteractive()) { $progress->display("Delete column {$target->name}.{$targetColumn->name}? "); if (!Garp_Spawn_Util::confirm()) { return; } } $target->deleteColumn($targetColumn); }
/** * @param Garp_Content_Upload_FileList &$conflictsByEtag A reference to the list that a matching entry should be added to * @param Garp_Content_Upload_FileNode $file The current file node within the Garp_Content_Upload_FileList * @return Void */ protected function _addEtagConflictingFile(Garp_Content_Upload_FileList &$conflictsByEtag, Garp_Content_Upload_FileNode $file) { $progress = Garp_Cli_Ui_ProgressBar::getInstance(); $filename = $file->getFilename(); $progress->display("Comparing {$filename}"); if (!$this->_matchEtags($file)) { $conflictsByEtag->addEntry($file); } $progress->advance(); }