예제 #1
0
파일: info.php 프로젝트: just-paja/fudjan
 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)));
     }
 }
예제 #2
0
파일: db.php 프로젝트: just-paja/fudjan
 public function cmd_migrate(array $params = array())
 {
     \System\Init::full();
     if (empty($params)) {
         $mig = \System\Database\Migration::get_new();
         array_reverse($mig);
         if (any($mig)) {
             $this->process_migrations($mig);
         } else {
             $this->vout("Did not find any usable migrations");
         }
     } else {
         $mig = $this->find_migrations($params[0]);
         if (any($mig)) {
             \Helper\Cli::out("Found " . count($mig) . " migration" . (count($mig) == 1 ? '' : 's') . ":");
             $this->print_migrations($mig, $padding = 2);
             \Helper\Cli::out("");
             \Helper\Cli::out("Do you wish to proceed? (y/n) ", false);
             $str = trim(shell_exec("read str; echo \$str"));
             if (in_array(strtolower($str), array("y", "1", "a"))) {
                 $this->save();
                 $this->process_migrations($mig);
             }
         } else {
             \Helper\Cli::out("Did not match any migration");
         }
     }
 }