本文整理汇总了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);
//.........这里部分代码省略.........
示例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;
}
}
示例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;
}