Microweber\Utils\Database::build_table PHP Метод

build_table() публичный Метод

public build_table ( $table_name, $fields_to_add, $use_cache = false )
    public function build_table($table_name, $fields_to_add, $use_cache = false)
    {
        if ($use_cache) {
            $key = 'mw_build_table' . $table_name;
            if (defined('MW_VERSION')) {
                $key = $key . MW_VERSION;
            }
            $value = Cache::get($key);
            if (!$value) {
                $value = 1;
                $minutes = $this->cache_minutes;
                Cache::put($key, $value, $minutes);
                return $this->_exec_table_builder($table_name, $fields_to_add);
            } else {
                return $value;
            }
        } else {
            return $this->_exec_table_builder($table_name, $fields_to_add);
        }
    }

Usage Example

Пример #1
0
 public function createSchema()
 {
     if (!DbSchema::hasTable('sessions')) {
         try {
             DbSchema::create('sessions', function ($table) {
                 $table->string('id')->unique();
                 $table->longText('payload');
                 $table->integer('last_activity');
             });
         } catch (QueryException $e) {
         }
     }
     $exec = $this->getSystemSchemas();
     $builder = new DbUtils();
     foreach ($exec as $data) {
         // Creates the schema
         if (!method_exists($data, 'get')) {
             break;
         }
         $schemaArray = $data->get();
         if (!is_array($schemaArray)) {
             break;
         }
         foreach ($schemaArray as $table => $columns) {
             $builder->build_table($table, $columns);
         }
     }
 }