當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Input::backupElement方法代碼示例

本文整理匯總了PHP中Terminus\Helpers\Input::backupElement方法的典型用法代碼示例。如果您正苦於以下問題:PHP Input::backupElement方法的具體用法?PHP Input::backupElement怎麽用?PHP Input::backupElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Terminus\Helpers\Input的用法示例。


在下文中一共展示了Input::backupElement方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: backups

 /**
  * Get, load, create, or list backup information
  *
  * ## OPTIONS
  *
  * <get|load|create|list>
  * : Function to run - get, load, create, or list
  *
  * [--site=<site>]
  * : Site to load
  *
  * [--env=<env>]
  * : Environment to load
  *
  * [--element=<code|files|db|all>]
  * : Element to download or create. `all` is only used for 'create'
  *
  * [--to=<directory|file>]
  * : Absolute path of a directory or filename to save the downloaded backup to
  *
  * [--file=<filename>]
  * : Select one of the files from the list subcommand. Only used for 'get'
  *
  * [--latest]
  * : If set the latest backup will be selected automatically
  *
  * [--keep-for]
  * : Number of days to keep this backup
  *
  * @subcommand backups
  *
  */
 public function backups($args, $assoc_args)
 {
     $action = array_shift($args);
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env($assoc_args, 'env'));
     //Backward compatability supports "database" as a valid element value.
     if (isset($assoc_args['element']) && $assoc_args['element'] == 'database') {
         $assoc_args['element'] = 'db';
     }
     switch ($action) {
         case 'get':
             $file = Input::optional('file', $assoc_args, false);
             if ($file) {
                 $backup = $env->getBackupByFile($file);
                 $element = $backup->element;
             } else {
                 $element = Input::backupElement(array('args' => $assoc_args));
                 $latest = (bool) Input::optional('latest', $assoc_args, false);
                 $backups = $env->getFinishedBackups($element);
                 if ($latest) {
                     $backup = array_pop($backups);
                 } else {
                     $context = array('site' => $site->get('name'), 'env' => $env->get('id'));
                     $backup = Input::backup(array('backups' => $backups, 'context' => $context));
                 }
             }
             $url = $env->getBackupUrl($backup->folder, $element);
             if (isset($assoc_args['to'])) {
                 $target = str_replace('~', $_SERVER['HOME'], $assoc_args['to']);
                 if (is_dir($target)) {
                     $filename = Utils\getFilenameFromUrl($url->url);
                     $target = sprintf('%s/%s', $target, $filename);
                 }
                 $this->log()->info('Downloading ... please wait ...');
                 if ($this->download($url->url, $target)) {
                     $this->log()->info('Downloaded {target}', compact('target'));
                     return $target;
                 } else {
                     $this->failure('Could not download file');
                 }
             }
             $this->output()->outputValue($url->url, 'Backup URL');
             return $url->url;
             break;
         case 'load':
             $assoc_args['to'] = '/tmp';
             $assoc_args['element'] = 'database';
             if (isset($assoc_args['database'])) {
                 $database = $assoc_args['database'];
             } else {
                 $database = escapeshellarg(Terminus::prompt('Name of database to import to'));
             }
             if (isset($assoc_args['username'])) {
                 $username = $assoc_args['username'];
             } else {
                 $username = escapeshellarg(Terminus::prompt('Username'));
             }
             if (isset($assoc_args['password'])) {
                 $password = $assoc_args['password'];
             } else {
                 $password = escapeshellarg(Terminus::prompt('Password'));
             }
             exec('mysql -e "show databases"', $stdout, $exit);
             if ($exit != 0) {
                 $this->failure('MySQL does not appear to be installed on your server.');
             }
             $assoc_args['env'] = $env->get('id');
             $target = $this->backup(array('get'), $assoc_args);
//.........這裏部分代碼省略.........
開發者ID:RobLoach,項目名稱:cli,代碼行數:101,代碼來源:site.php

示例2: listBackups

 /**
  * Lists available backups
  *
  * @params [array] $assoc_args Parameters and flags from the command line
  * @return [array] $data Elements as follows:
  *         [string] file The backup's file name
  *         [string] size The backup file's size
  *         [string] date The datetime of the backup's creation
  */
 private function listBackups($assoc_args)
 {
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env(array('args' => $assoc_args, 'site' => $site)));
     $element = null;
     if (isset($assoc_args['element']) && $assoc_args['element'] != 'all') {
         $element = Input::backupElement(array('args' => $assoc_args));
     }
     $backups = $env->backups->getFinishedBackups($element);
     $latest = (bool) Input::optional('latest', $assoc_args, false);
     if (empty($backups)) {
         $this->log()->warning('No backups found.');
     } else {
         if ($latest) {
             array_splice($backups, 1);
         }
         $data = array();
         foreach ($backups as $id => $backup) {
             $data[] = array('file' => $backup->get('filename'), 'size' => $backup->getSizeInMb(), 'date' => $backup->getDate(), 'initiator' => $backup->getInitiator());
         }
         return $data;
     }
 }
開發者ID:4aficiona2,項目名稱:cli,代碼行數:32,代碼來源:SiteCommand.php

示例3: getBackup

 /**
  * Retrieves a single backup or downloads it as requested
  *
  * @params [array] $assoc_args Parameters and flags from the command line
  * @return [string] $url->url
  */
 private function getBackup($assoc_args)
 {
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env(array('args' => $assoc_args, 'site' => $site)));
     $file = Input::optional('file', $assoc_args, false);
     if ($file) {
         $backup = $env->getBackupByFile($file);
         $element = $backup->element;
     } else {
         $element = Input::backupElement(array('args' => $assoc_args));
         $latest = (bool) Input::optional('latest', $assoc_args, false);
         $backups = $env->getFinishedBackups($element);
         if ($latest) {
             $backup = array_pop($backups);
         } else {
             $context = array('site' => $site->get('name'), 'env' => $env->get('id'));
             $backup = Input::backup(array('backups' => $backups, 'context' => $context));
         }
     }
     $url = $env->getBackupUrl($backup->folder, $element);
     if (isset($assoc_args['to'])) {
         $target = str_replace('~', $_SERVER['HOME'], $assoc_args['to']);
         if (is_dir($target)) {
             $filename = Utils\getFilenameFromUrl($url->url);
             $target = sprintf('%s/%s', $target, $filename);
         }
         $this->log()->info('Downloading ... please wait ...');
         if (Request::download($url->url, $target)) {
             $this->log()->info('Downloaded {target}', compact('target'));
             return $target;
         } else {
             $this->failure('Could not download file');
         }
     }
     return $url->url;
 }
開發者ID:bjargud,項目名稱:cli,代碼行數:42,代碼來源:SiteCommand.php


注:本文中的Terminus\Helpers\Input::backupElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。