protected function _populateRecordsForModel($modelName) { Garp_Cli::lineOut("Updating model " . $modelName, Garp_Cli::YELLOW); $model = $this->_getModel($modelName); $i18nModel = $model->getObserver('Translatable')->getI18nModel($model); $foreignKeyColumns = $this->_getForeignKeyColumns($i18nModel, $model); // Trigger an update on the record and let Translatable behavior do the work $records = $this->_fetchRecordsInDefaultLanguage($model); foreach ($records as $record) { $foreignKeyWhereClause = $this->_getForeignKeyWhereClause($record, $model, $foreignKeyColumns); $fkValue = $record[$foreignKeyColumns[0]]; unset($record[$foreignKeyColumns[0]]); $updateData = array_map(function ($value) { return array(Garp_I18n::getDefaultLocale() => $value); }, $record->toArray()); unset($updateData['slug']); // Bit of a hack but if we only select multilingual fields Translatable will strip 'em // out and leave an empty UPDATE statement. Put id in there to give UPDATE statement // some body. $updateData['id'] = $fkValue; // Update with existing data. Translatable should pick up and populate other-language // records where applicable. try { $model->update($updateData, $foreignKeyWhereClause); } catch (Garp_Model_Validator_Exception $e) { Garp_Cli::errorOut('Could not update record ' . $updateData['id'] . ' because of exception:'); Garp_Cli::errorOut($e->getMessage()); } } Garp_Cli::lineOut('Done.'); }
public function help() { Garp_Cli::lineOut("☞ U s a g e :\n"); Garp_Cli::lineOut("Distributing all assets to the CDN servers:"); Garp_Cli::lineOut("\tgarp.php Cdn distribute"); Garp_Cli::lineOut(""); Garp_Cli::lineOut("Examples of distributing a specific set of assets to the CDN servers:"); Garp_Cli::lineOut("\tgarp.php Cdn distribute main.js"); Garp_Cli::lineOut("\tgarp.php Cdn distribute css"); Garp_Cli::lineOut("\tgarp.php Cdn distribute css/icons"); Garp_Cli::lineOut("\tgarp.php Cdn distribute logos"); Garp_Cli::lineOut(""); Garp_Cli::lineOut("Distributing to a specific environment:"); Garp_Cli::lineOut("\tgarp.php Cdn distribute --to=development"); Garp_Cli::lineOut("\tgarp.php Cdn distribute main.js --to=staging"); Garp_Cli::lineOut(""); Garp_Cli::lineOut("Default only recently modified files will be distributed."); Garp_Cli::lineOut("To distribute all files:"); Garp_Cli::lineOut("\tgarp.php Cdn distribute --since=forever"); Garp_Cli::lineOut(""); Garp_Cli::lineOut("To distribute files modified since a specific date " . "(use a 'strtotime' compatible argument):"); Garp_Cli::lineOut("\tgarp.php Cdn distribute --since=yesterday"); Garp_Cli::lineOut(""); Garp_Cli::lineOut("To see which files will be distributed without actually " . "distributing them, do a dry run:"); Garp_Cli::lineOut("\tgarp.php Cdn distribute --dry"); Garp_Cli::lineOut(""); }
/** * Minify assets * * @param array $args * @return bool */ public function minifyJs(array $args = array()) { $ini = Zend_Registry::get('config'); if (empty($ini->assets->js)) { Garp_Cli::errorOut("You do not have a valid asset configuration specified in application.ini.\n" . "Configure like this:\n" . 'assets.js.main_js.filename = "main.min.js"' . "\n" . 'assets.js.main_js.sourcefiles[] = "libs/myplugin.js"' . "\n" . 'assets.js.main_js.sourcefiles[] = "main.js"' . "\n" . "This will combine libs/myplugin.js and main.js into main.min.js."); return false; } $jsRoot = ltrim($ini->assets->js->basePath ?: 'js', '/'); $assets = $ini->assets->js->toArray(); unset($assets['basePath']); $selectedKey = null; if (!empty($args)) { $selectedKey = $args[0]; } foreach ($assets as $key => $assetSettings) { if (!is_null($selectedKey) && $key != $selectedKey) { continue; } if (empty($assetSettings['sourcefiles']) || empty($assetSettings['filename'])) { Garp_Cli::errorOut($key . ' is not configured correctly. "sourcefiles" and "filename" are required keys.'); return false; } $minifier = new Garp_Assets_Minifier(APPLICATION_PATH . '/../public/' . $jsRoot); $minifier->minifyJs($assetSettings['sourcefiles'], $assetSettings['filename']); } Garp_Cli::lineOut('Done.'); return true; }
/** * @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"; }
/** * Cleanup log files * * @param array $args * @return bool */ public function clean(array $args = array()) { // Resolve parameters $logRoot = array_get($args, 'root', APPLICATION_PATH . '/data/logs'); $pattern = array_get($args, 'pattern', '/\\.log$/i'); $threshold = array_get($args, 'threshold', '1 month ago'); $verbose = array_get($args, 'verbose', false); $count = 0; $leanOut = ''; $verboseOut = ''; if ($handle = opendir($logRoot)) { while (false !== ($entry = readdir($handle))) { $isLogFile = preg_match($pattern, $entry); $isTooOld = filemtime($logRoot . '/' . $entry) < strtotime($threshold); if ($isLogFile && $isTooOld) { @unlink($logRoot . '/' . $entry); ++$count; $verboseOut .= " - {$entry}\n"; } } $leanOut = "{$count} log files successfully removed"; $verboseOut = $leanOut . ":\n" . $verboseOut; closedir($handle); } if ($count) { if ($verbose) { Garp_Cli::lineOut($verboseOut); } else { Garp_Cli::lineOut($leanOut); } } else { Garp_Cli::lineOut('No log files matched the given criteria.'); } return true; }
/** * Help * * @return bool */ public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut('Send Slack message:'); Garp_Cli::lineOut(' g slack send "Hello world"', Garp_Cli::BLUE); Garp_Cli::lineOut(''); return true; }
/** * Help * * @return bool */ public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut('Display "Eat My Shorts":'); Garp_Cli::lineOut(' g Figlet display Eat My Shorts'); Garp_Cli::lineOut(''); return true; }
/** * Help * * @return bool */ public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut('Setup Git environment'); Garp_Cli::lineOut(' g Git setup', Garp_Cli::BLUE); Garp_Cli::lineOut(''); return true; }
public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut(' g hotfix start', Garp_Cli::BLUE); Garp_Cli::lineOut(' g hotfix finish', Garp_Cli::BLUE); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Note: this requires the git flow and semver commandline utilities.'); }
/** * Help * * @return bool */ public function help() { Garp_Cli::lineOut('Generate slugs for existing records'); Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut(' g Slugs generate <model name> <overwrite>'); Garp_Cli::lineOut(''); return true; }
/** * Display help * * @return void */ public function help() { Garp_Cli::lineOut('This is a wrapper around Amazon awscmd.', Garp_Cli::YELLOW); Garp_Cli::lineOut("Make sure it's " . "installed on your machine (go to http://aws.amazon.com/cli/ for instructions)"); Garp_Cli::lineOut('Note that this wrapper manages your awscmd profiles for you.'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Use S3 accounts of ' . 'various environments by adding the usual --e parameter:'); Garp_Cli::lineOut(' g aws s3 ls uploads/ --e=production', Garp_Cli::BLUE); }
public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut(' g feature start discombobulator', Garp_Cli::BLUE); Garp_Cli::lineOut(' g feature finish', Garp_Cli::BLUE); Garp_Cli::lineOut(' g feature publish', Garp_Cli::BLUE); Garp_Cli::lineOut(' g feature track discombobulator', Garp_Cli::BLUE); Garp_Cli::lineOut('Note: this requires the git flow and semver commandline utilities.'); }
public function main(array $args = array()) { $domain = isset(Zend_Registry::get('config')->app->domain) ? Zend_Registry::get('config')->app->domain : null; if (!$domain) { Garp_Cli::errorOut('No domain found. Please configure app.domain'); return false; } `open http://{$domain}`; return true; }
/** * Help * * @return bool */ public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut('Clear all cache:'); Garp_Cli::lineOut(' g Cache clear', Garp_Cli::BLUE); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Clear cache of model Foo and model Bar:'); Garp_Cli::lineOut(' g Cache clear Model_Foo Model_Bar', Garp_Cli::BLUE); Garp_Cli::lineOut(''); return true; }
/** * Migrate garp to the composer version. * * @return bool */ public function migrate() { $this->_requireGarpComposerPackage(); $this->_updateSymlinks(); $this->_updateIndexPhp(); $this->_updateLocaleFiles(); $this->_updateRoutesInclude(); $this->_updateCapFile(); Garp_Cli::lineOut('Done!'); Garp_Cli::lineOut('I\'m leaving the original garp folder in case you ' . 'still have to push something from the subtree.', Garp_Cli::BLUE); return true; }
public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut(' g release start', Garp_Cli::BLUE); Garp_Cli::lineOut(' g release finish', Garp_Cli::BLUE); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Determine the type of version bump: (default is minor)'); Garp_Cli::lineOut(' g release start major|minor', Garp_Cli::BLUE); Garp_Cli::lineOut('Or do a "special" release:'); Garp_Cli::lineOut(' g release start "beta"'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Note: this requires the git flow and semver commandline utilities.'); }
/** * Help * * @return bool */ public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut(' g Env setup', Garp_Cli::BLUE); Garp_Cli::lineOut(''); Garp_Cli::lineOut('To enable under construction:'); Garp_Cli::lineOut(' g Env setUnderConstruction', Garp_Cli::BLUE); Garp_Cli::lineOut(''); Garp_Cli::lineOut('To disable under construction:'); Garp_Cli::lineOut(' g Env setUnderConstruction false', Garp_Cli::BLUE); Garp_Cli::lineOut(''); return true; }
public function get($args) { $key = $args[0]; $env = isset($args[1]) ? $args[1] : APPLICATION_ENV; $application = Zend_Registry::get('application'); $configFile = $application->getConfigFile(); $application = new Garp_Application($env, $configFile); $conf = $application->getOptions(); $bits = explode('.', $key); while (isset($bits[0]) && isset($conf[$bits[0]])) { $conf = $conf[$bits[0]]; array_shift($bits); } Garp_Cli::lineOut(is_array($conf) ? print_r($conf, true) : $conf); return true; }
/** * Help method * * @return bool */ public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut('Test everything:'); Garp_Cli::lineOut(' g Test'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Only execute Garp tests:'); Garp_Cli::lineOut(' g Test --module=garp'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Only execute App tests:'); Garp_Cli::lineOut(' g Test --module=default'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Execute Garp tests within the group "Cache":'); Garp_Cli::lineOut(' g Test --module=garp --group=Cache'); Garp_Cli::lineOut(''); return true; }
public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut('Verify email address:'); Garp_Cli::lineOut(' g Ses verify <email address>'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Delete email address:'); Garp_Cli::lineOut(' g Ses delete <email address>'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('List verified email addresses:'); Garp_Cli::lineOut(' g Ses listAddresses'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('See send quota:'); Garp_Cli::lineOut(' g Ses quota'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('See send statistics:'); Garp_Cli::lineOut(' g Ses stats'); Garp_Cli::lineOut(''); return true; }
public function restore($args = array()) { $mem = new Garp_Util_Memory(); $mem->useHighMemory(); $version = new Garp_Semver(); Garp_Cli::lineOut('Restoring gumball ' . $version, Garp_Cli::PURPLE); $gumball = new Garp_Gumball($version); try { $gumball->restore(); $this->_broadcastGumballInstallation($version); Garp_Cli::lineOut('Done!', Garp_Cli::GREEN); } catch (Garp_Gumball_Exception_SourceEnvNotConfigured $e) { Garp_Cli::errorOut(self::ERROR_SOURCE_ENV_NOT_CONFIGURED); return false; } catch (Exception $e) { Garp_Cli::errorOut('Error: ' . $e->getMessage()); return false; } return true; }
/** * Force user to confirm a question with yes or no. * * @param string $msg Question or message to display. A prompt (>) will be added. * @return bool Returns true if answer was 'y' or 'Y', no enter needed. */ public static function confirm($msg) { print $msg . ' > '; system('stty -icanon'); $handle = fopen('php://stdin', 'r'); $char = fgetc($handle); system('stty icanon'); print "\n"; $allowedResponses = array('y', 'Y', 'n', 'N'); if (!in_array($char, $allowedResponses)) { // nag 'em some more Garp_Cli::errorOut('Please respond with a clear y or n'); return static::confirm($msg); } return $char === 'y' || $char === 'Y'; }
public function displayHeader($string) { return Garp_Cli::lineOut("\n" . $string); }
/** * Make sure the method is not inadvertently called with the * wrong arguments. This might indicate the user made a mistake * in calling it. * * @param string $methodName * @param array $args * @return bool */ protected function _validateArguments($methodName, $args) { if (!array_key_exists($methodName, $this->_allowedArguments) || $this->_allowedArguments[$methodName] === '*') { return true; } $unknownArgs = array_diff(array_keys($args), $this->_allowedArguments[$methodName]); if (!count($unknownArgs)) { return true; } // Report the first erroneous argument $errorStr = current($unknownArgs); // Show the value of the argument if the index is numeric if (is_numeric($errorStr)) { $errorStr = $args[$unknownArgs[0]]; } Garp_Cli::errorOut('Unexpected argument ' . $errorStr); return false; }
protected function _validateSyncArguments(array $args) { $valid = false; $argCount = count($args); if (!array_key_exists(0, $args)) { Garp_Cli::errorOut("No source environment provided."); } elseif (!array_key_exists(1, $args)) { Garp_Cli::errorOut("No target environment provided."); } elseif (!in_array($args[0], $this->_environments)) { Garp_Cli::errorOut("Source environment is invalid. Try: " . Garp_Util_String::humanList($this->_environments, null, 'or') . '.'); } elseif (!in_array($args[1], $this->_environments)) { Garp_Cli::errorOut("Target environment is invalid. Try: " . Garp_Util_String::humanList($this->_environments, null, 'or') . '.'); } else { $valid = true; } if (!$valid) { $this->help(); return false; } return true; }
public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut(' g ssh staging', Garp_Cli::BLUE); return true; }
public function displayError($string) { return Garp_Cli::errorOut($string); }
/** * Help * * @return bool */ public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut(' g permissions set', Garp_Cli::BLUE); return true; }
public function help() { Garp_Cli::lineOut('Usage:'); Garp_Cli::lineOut('To create snippets from /application/configs/snippets.ini:'); Garp_Cli::lineOut(' g snippet create', Garp_Cli::BLUE); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Or to create snippets from a custom file:'); Garp_Cli::lineOut(' g snippet create --file=myfile.ini', Garp_Cli::BLUE); Garp_Cli::lineOut(''); Garp_Cli::lineOut('Overwrite existing snippets:'); Garp_Cli::lineOut(' g snippet create --overwrite'); Garp_Cli::lineOut(''); Garp_Cli::lineOut('To create a snippet interactively:'); Garp_Cli::lineOut(' g snippet create -i', Garp_Cli::BLUE); Garp_Cli::lineOut(''); Garp_Cli::lineOut('To add system snippets for an internationalized website:'); Garp_Cli::lineOut(' g snippet storeI18nStrings', Garp_Cli::BLUE); Garp_Cli::lineOut(''); }
protected function _displayHelp() { Garp_Cli::lineOut("Commands"); Garp_Cli::lineOut("g postcodenl import ~/pcdata.csv", Garp_Cli::BLUE); Garp_Cli::lineOut("Where the last argument is the path to the 6PP CSV file from postcode.nl."); }