public function cmd_list() { \System\Init::basic(); $list = cfg('assets', 'dependencies'); if ($this->json) { \Helper\Cli::out(json_encode(array("dependencies" => $list), JSON_PRETTY_PRINT)); } else { \Helper\Cli::out('Bower dependencies'); \Helper\Cli::out_flist(array("list" => $list, "margin" => 2)); } }
public function cmd_restore(array $params = array()) { \System\Init::basic(); if (isset($params[0])) { if (file_exists($params[0])) { $db_ident = cfg('database', 'default'); $db_name = cfg('database', 'list', $db_ident, 'database'); $this->vout("Restoring database '" . $db_name . "'"); if (!self::database_exists()) { $this->database_create(); } if ($this->json) { $this->import_json($params[0]); } else { $this->import_sql($params[0]); } \Helper\Cli::out("Database restored"); } else { give_up("File not found!", 5); } } else { $backups = array(); $files = array(); $d = opendir(BASE_DIR . "/var/backups"); while ($f = readdir($d)) { if (strpos($f, ".") !== 0 && strpos($f, ".sql")) { $name = explode('_', $f); $backups[] = $name[0]; $files[] = $f; } } rsort($backups); rsort($files); if (any($backups)) { \Helper\Cli::out("Found these backups:"); \Helper\Cli::out_flist(array("list" => $backups, "margin" => 2)); \Helper\Cli::out(''); $key = $this->force ? 0 : \Helper\Cli::read("Pick one [0-" . count($backups) . "]: ", false); if (array_key_exists($key, $backups)) { if ($this->database_exists()) { $this->cmd('drop'); } $this->database_create(); \Helper\Cli::out("Restoring to: " . $backups[$key]); self::import_sql(BASE_DIR . "/var/backups/" . $files[$f]); \Helper\Cli::out("Database restored"); } else { give_up("Invalid option."); } } else { give_up("Did not find any backups"); } } }
public static function cmd_database() { \System\Init::full(); $db_list = \System\Settings::get('database', 'list'); foreach ($db_list as $db_ident => $db_cfg) { $size = \System\Database::query("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t\tsum(data_length + index_length) 'size',\n\t\t\t\t\t\t\tsum( data_free ) 'free'\n\t\t\t\t\t\tFROM information_schema.TABLES\n\t\t\t\t\t\tWHERE table_schema = '" . $db_cfg['database'] . "'\n\t\t\t\t\t\tGROUP BY table_schema;\n\t\t\t\t")->fetch(); $mlast_date = false; $mcount = 0; try { $mig = \System\Database\Migration::get_new(); $mcount = count($mig); $stat = "Ok"; $mlast = \System\Database\Migration::get_first()->where(array("status" => 'ok'))->sort_by("updated_at DESC")->fetch(); if ($mlast) { $mlast_date = $mlast->updated_at; } } catch (System\Error $e) { $stat = "Migrating database is necessary."; } \Helper\Cli::out('Database ' . $db_ident); \Helper\Cli::sep(); \Helper\Cli::out_flist(array("list" => array("Driver" => $db_cfg['driver'], "Host name" => $db_cfg['host'], "Database name" => $db_cfg['database'], "User" => $db_cfg['username'], "Used charset" => $db_cfg['charset'], "Lazy driver" => $db_cfg['lazy'] ? 'yes' : 'no', "Size" => \System\Template::convert_value('information', $size['size']), "Free space" => \System\Template::convert_value('information', $size['free']), "Structure" => $stat, "Last migrated" => $mlast_date ? $mlast_date->format('Y-m-d H:i:s') : 'never', "New migrations" => $mcount))); } }
public static function cmd_list() { \Helper\Cli::out_flist(array("list" => self::get_all(), "show_keys" => false)); }
/** Display usage * @return void */ public function usage() { $cmd_list = array(); $opt_list = array(); foreach ($this::$commands as $cmd => $info) { if (is_array($info)) { foreach ($info as $type => $desc) { $cmd_list[$type == 'single' ? $cmd : $cmd . " '" . $type . "'"] = $desc; } } else { $cmd_list[$cmd] = $info; } } foreach ($this::$attrs as $opt => $info) { if (isset($info['desc'])) { $name = (isset($info['short']) ? '-' . $info['short'] . ' ' : ' ') . '--' . $opt; $opt_list[$name] = $info['desc']; } } \Helper\Cli::out(is_array($this::$info['head']) ? implode("\n", $this::$info['head']) : $this::$info['head']); \Helper\Cli::out(); \Helper\Cli::out("Usage:"); \Helper\Cli::out(" ./" . $this->get_name() . " " . $this::$accepts); \Helper\Cli::out(" ./" . $this->get_name() . " " . $this::$accepts . " [params]"); \Helper\Cli::out(); if (!empty($cmd_list)) { \Helper\Cli::out("Commands:"); \Helper\Cli::out_flist(array("list" => $cmd_list, "semicolon" => false, "margin" => 2)); \Helper\Cli::out(); } if (!empty($opt_list)) { \Helper\Cli::out("Options:"); \Helper\Cli::out_flist(array("list" => $opt_list, "semicolon" => false, "margin" => 2)); } exit; }