예제 #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
 public static function seed_initial_data()
 {
     if (static::has_been_seeded()) {
         return;
     }
     foreach (self::$initial_data as $model => $objects) {
         foreach ($objects as $data_set) {
             if (isset($data_set['password'])) {
                 $data_set['password'] = hash_passwd($data_set['password']);
             }
             $obj = null;
             if (isset($data_set['id'])) {
                 $obj = $model::find($data_set['id']);
             }
             if ($obj) {
                 $obj->update_attrs($data_set);
             } else {
                 $obj = new $model($data_set);
                 $obj->is_new_object = true;
             }
             $obj->save();
             foreach ($data_set as $attr => $val) {
                 if (is_array($val) && $model::has_attr($attr) && $model::is_rel($attr)) {
                     if ($model::get_attr_type($attr) == 'has-many') {
                         $def = $model::get_attr($attr);
                         if (any($def['is_bilinear']) && any($def['is_master'])) {
                             unset($obj->{$attr});
                             $obj->assign_rel($attr, $val);
                         }
                     }
                 }
             }
         }
     }
     \System\Database\Migration::create(array('seoname' => 'initial-seed', 'name' => 'Initial data seed', 'desc' => 'Initial data seed', 'status' => 'ok', 'date' => new \DateTime()));
 }
예제 #3
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");
         }
     }
 }