function create_demo() { $db_line = color(str_repeat('=', 80), 'N') . "\n"; $line = color(str_repeat('-', 80), 'w') . "\n"; echo $db_line; $results = array(); $migrations = array('event' => array(), 'attendee' => array(), 'tag' => array(), 'tag_event_map' => array()); array_walk($migrations, function ($value, $key) use(&$results) { array_push($results, implode("\n", array_map(function ($result) { $count = 1; return color(' Create: ', 'g') . str_replace(FCPATH, '', $result, $count); }, create_migration(BASEPATH . 'cmd/templates/demo/' . $key . '/', $key, 'add')))); }); echo implode("\n", $results) . "\n" . $line; $results = array(); $models = array('event' => array('-p' => array('cover')), 'attendee' => array(), 'tag' => array(), 'tag_event_map' => array()); array_walk($models, function ($value, $key) use(&$results) { array_push($results, implode("\n", array_map(function ($result) { $count = 1; return color(' Create: ', 'g') . str_replace(FCPATH, '', $result, $count); }, create_model(BASEPATH . 'cmd/templates/demo/' . $key . '/', $key, isset($value['-p']) ? $value['-p'] : array(), isset($value['-f']) ? $value['-f'] : array())))); }); echo implode("\n", $results) . "\n" . $line; $results = array(); $cells = array('demo' => array('main_menu')); array_walk($cells, function ($value, $key) use(&$results) { array_push($results, implode("\n", array_map(function ($result) { $count = 1; return color(' Create: ', 'g') . str_replace(FCPATH, '', $result, $count); }, create_cell(BASEPATH . 'cmd/templates/demo/cell/', $key, $value)))); }); echo implode("\n", $results) . "\n" . $line; $results = array(); $controllers = array('events' => array(), 'tags' => array()); array_walk($controllers, function ($value, $key) use(&$results) { array_push($results, implode("\n", array_map(function ($result) { $count = 1; return color(' Create: ', 'g') . str_replace(FCPATH, '', $result, $count); }, create_controller(BASEPATH . 'cmd/templates/demo/' . singularize($key) . '/', $key, 'site', array('index', 'show', 'add', 'create', 'edit', 'update', 'destroy'))))); }); echo implode("\n", $results) . "\n" . $line; $results = run_migration(null); echo color('注意! ', 'r'); echo implode("\n", $results) . "\n"; $results = array(); array_push($results, "migrations(" . implode(', ', array_keys($migrations)) . ")"); array_push($results, "models(" . implode(', ', array_keys($models)) . ")"); array_push($results, "cells(" . implode(', ', array_keys($cells)) . ")"); array_push($results, "controllers(" . implode(', ', array_keys($controllers)) . ")"); return $results; }
<?php /** * @author OA Wu <*****@*****.**> * @copyright Copyright (c) 2015 OA Wu Design */ include_once 'base.php'; include_once 'functions/migration.php'; // file version // ========================================== // php migration [0 | 1 | 2...] $file = array_shift($argv); $version = array_shift($argv); $results = run_migration($version); array_unshift($results, '更新成功!'); call_user_func_array('console_log', $results);
Migration::create_database(MYSQL_DATABASE); } //load the test database if (!defined('DATABASE_CREATED')) { reload_database_tables(); define('DATABASE_CREATED', true); } function run_migration() { $g = new TestMigration(); $g->down(); $g->up(); } //load the table if it hasn't been loaded if (!defined('TABLE_CREATED')) { run_migration(); user_data(); define('TABLE_CREATED', true); } function create_users() { foreach (range(1, 10) as $i) { User::_create(array('name' => 'names' . $i, 'my_int' => $i)); } } function fill_user_photos() { $users = User::find_all(); foreach ($users as $user) { create_user_photos($user->id); }