示例#1
0
 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.');
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * @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";
 }
示例#4
0
 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("");
 }
示例#5
0
 /**
  * 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;
 }
示例#6
0
 /**
  * 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;
 }
示例#7
0
 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.');
 }
示例#8
0
 /**
  * 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;
 }
示例#9
0
 /**
  * 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;
 }
示例#10
0
 /**
  * Assists in bash completion
  *
  * @param array $args
  * @return bool
  */
 public function complete(array $args = array())
 {
     $publicMethods = $this->getPublicMethods();
     $ignoredMethods = array('complete');
     $publicMethods = array_diff($publicMethods, $ignoredMethods);
     Garp_Cli::lineOut(implode(' ', $publicMethods));
     return true;
 }
示例#11
0
 /**
  * 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;
 }
示例#12
0
 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.');
 }
示例#13
0
 /**
  * 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);
 }
示例#14
0
 /**
  * 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;
 }
示例#15
0
 /**
  * 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;
 }
示例#16
0
 /**
  * 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;
 }
示例#17
0
 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.');
 }
示例#18
0
 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;
 }
示例#19
0
 /**
  * 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;
 }
示例#20
0
 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;
 }
示例#21
0
 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;
 }
示例#22
0
 protected function _syncUploads()
 {
     $progress = Garp_Cli_Ui_ProgressBar::getInstance();
     $progress->init(1);
     $progress->display('Analyzing');
     $mediator = new Garp_Content_Upload_Mediator($this->_sourceEnv, $this->_targetEnv);
     $transferList = $mediator->fetchDiff();
     $progress->display("√ Done comparing");
     if ($transferTotal = count($transferList)) {
         Garp_Cli::lineOut("\n\nSyncing uploads");
         /*  total * 2, because both fetching the source and storing
             on target count as an advance on the progressbar. */
         $progress->init($transferTotal * 2);
         $mediator->transfer($transferList);
         $progress->display("√ Transferred {$transferTotal} files");
     } else {
         $progress->advance();
         $progress->display("√ Done, no files to transfer");
     }
 }
示例#23
0
 protected function _getInsertionMode()
 {
     $query = 'Want to create a record (i)nteractively or shall I just ' . 'insert a bunch of (g)ibberish?';
     $response = Garp_Cli::prompt($query);
     if (in_array($response, array('i', 'g'))) {
         return $response;
     }
     Garp_Cli::lineOut('Please answer "i" or "g"');
     return $this->_getInsertionMode();
 }
示例#24
0
 protected function _indexModel(Garp_Spawn_Model_Abstract $model)
 {
     if (!$this->_isElasticsearchable($model)) {
         return;
     }
     $phpModel = $this->_getPhpModel($model);
     $phpBehavior = $this->_getPhpBehavior($phpModel);
     if (!$phpBehavior->getRootable()) {
         return;
     }
     $records = $this->_fetchAllIds($phpModel);
     foreach ($records as $record) {
         $this->_pushRecord($phpModel, $phpBehavior, $record);
     }
     $report = sprintf('Indexed %d %s records', count($records), $model->id);
     Garp_Cli::lineOut($report);
 }
示例#25
0
 public function displayHeader($string)
 {
     return Garp_Cli::lineOut("\n" . $string);
 }
示例#26
0
 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.");
 }
示例#27
0
 public function help()
 {
     Garp_Cli::lineOut('Usage:');
     Garp_Cli::lineOut(' g ssh staging', Garp_Cli::BLUE);
     return true;
 }
示例#28
0
 /**
  * Help
  *
  * @return bool
  */
 public function help()
 {
     Garp_Cli::lineOut('Usage:');
     Garp_Cli::lineOut(' g permissions set', Garp_Cli::BLUE);
     return true;
 }
示例#29
0
 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('');
 }
示例#30
0
 /**
  * Check if semver and git flow are installed
  *
  * @return bool
  */
 protected function _required_tools_available()
 {
     $semver_checker = shell_exec('which semver');
     if (empty($semver_checker)) {
         Garp_Cli::errorOut('semver is not installed');
         Garp_Cli::lineOut('Install like this:');
         Garp_Cli::lineOut(' gem install semver', Garp_Cli::BLUE);
         return false;
     }
     /*
        @todo REFACTOR LATER! Check fails on Ubuntu?
             $gitflow_checker = shell_exec('which git-flow');
             if (empty($gitflow_checker)) {
        Garp_Cli::errorOut('git-flow is not installed');
        Garp_Cli::lineOut('Get it from brew');
        Garp_Cli::lineOut(' brew install git-flow', Garp_Cli::BLUE);
        return false;
             }
     */
     return true;
 }