<?php /** * dao data export * @param string $file */ if (empty($file)) { $file = getcwd() . '/dump.ddj'; } \org\rhaco\io\File::write($file, ''); foreach (\org\rhaco\Dt::classes('\\org\\rhaco\\store\\db\\Dao') as $class_info) { $r = new \ReflectionClass($class_info['class']); if ($r->getParentClass()->getName() == 'org\\rhaco\\store\\db\\Dao') { \cmdman\Std::println_info('Find ' . $r->getName()); \org\rhaco\io\File::append($file, '[[' . $r->getName() . ']]' . PHP_EOL); $find = call_user_func(array($r->getName(), 'find')); foreach ($find as $obj) { \org\rhaco\io\File::append($file, json_encode($obj->props()) . PHP_EOL); } } } \cmdman\Std::println_success('Written ' . $file);
}; $update = $failure = []; foreach ($get_dao_dump_func($file) as $arr) { $ref = new \ReflectionClass($arr['model']); $inst = $ref->newInstance(); if (!array_key_exists($ref->getName(), $failure)) { try { foreach ($inst->props() as $k => $v) { if (array_key_exists($k, $arr['data'])) { if ($inst->prop_anon($k, 'cond') == null && $inst->prop_anon($k, 'extra', false) === false) { $inst->prop_anon($k, 'auto_now', false, true); call_user_func_array([$inst, $k], [$arr['data'][$k]]); } } } $inst->save(); if (!array_key_exists($ref->getName(), $update)) { $update[$ref->getName()] = 0; } $update[$ref->getName()]++; } catch (\ebi\exception\BadMethodCallException $e) { $failure[$ref->getName()] = true; } } } foreach ($update as $class_name => $cnt) { \cmdman\Std::println_info(' Import ' . $class_name . ' (' . $cnt . ')'); } foreach (array_keys($failure) as $class_name) { \cmdman\Std::println_danger(' Failure ' . $class_name); }
* dao data import * @param string $file */ if (empty($file)) { $file = getcwd() . '/dump.ddj'; } $dao_list = array(); foreach (\org\rhaco\Dt::classes('\\org\\rhaco\\store\\db\\Dao') as $class_info) { $r = new \ReflectionClass($class_info['class']); if ($r->getParentClass()->getName() == 'org\\rhaco\\store\\db\\Dao') { $dao_list[] = $r->getName(); } } $current = null; $fp = fopen($file, 'rb'); \cmdman\Std::println_info('Load ' . $file); while (!feof($fp)) { $line = fgets($fp); if (!empty($line)) { if ($line[0] == '[') { $current = null; $class = preg_replace('/\\[\\[(.+)\\]\\]/', '\\1', trim($line)); if (in_array($class, $dao_list)) { $ref = new \ReflectionClass($class); $current = $ref->newInstance(); \cmdman\Std::println_success('Update ' . get_class($current)); } } else { if ($line[0] == '{' && !empty($current)) { $obj = clone $current; $arr = json_decode($line, true);
$cmddir = defined('COMMONDIR') ? constant('COMMONDIR') : getcwd() . '/commons'; $mode_list = array(); if (is_dir($cmddir)) { foreach (new \RecursiveDirectoryIterator($cmddir, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS) as $f) { if (substr($f->getFilename(), -4) == '.php') { $mode_list[] = substr($f->getFilename(), 0, -4); } } } $default = empty($appmode) || array_search($appmode, $mode_list) !== false ? $appmode : 'local'; $mode = \cmdman\Std::read('Application mode', $default, $mode_list); $settings_file = getcwd() . '/__settings__.php'; file_put_contents($settings_file, '<?php' . PHP_EOL . 'define(\'APPMODE\',\'' . $mode . '\');' . PHP_EOL . 'define(\'COMMONDIR\',\'' . $cmddir . '\');' . PHP_EOL); \cmdman\Std::println_success('Written: ' . realpath($settings_file)); if ($mode != $appmode) { \cmdman\Std::println_info('Application mode changed.'); exit; } if (\cmdman\Std::read('create .htaccess?', 'n', array('y', 'n')) == 'y') { $base = \cmdman\Std::read('base path?', '/' . basename(getcwd())); list($path, $rules) = \org\rhaco\Dt::htaccess($base); \cmdman\Std::println_success('Written ' . realpath($path)); } $setup_cmd = substr(\org\rhaco\Dt::setup_file(), 0, -4) . '.cmd.php'; if (is_file($setup_cmd)) { include $setup_cmd; } if (is_file($f = \org\rhaco\Dt::setup_file())) { \cmdman\Std::println_success('Loading ' . $f); \org\rhaco\Dt::setup(); }
<?php /** * .htaccessを書き出す * @param string $base */ if (!isset($base)) { $base = '/' . basename(getcwd()); } list($path, $rules) = \org\rhaco\Dt::htaccess($base); \cmdman\Std::println_success('Written: ' . $path); \cmdman\Std::println_default(str_repeat('-', 60)); \cmdman\Std::println_info(trim($rules)); \cmdman\Std::println_default(str_repeat('-', 60));
foreach (\ebi\Dt::classes(\ebi\Dao::class) as $class_info) { $class_name = \ebi\Util::get_class_name($class_info['class']); try { call_user_func([$class_name, 'find_get']); \cmdman\Std::println_success(' ' . $class_name . ' OK'); } catch (\ebi\exception\NotFoundException $e) { } catch (\ebi\exception\ConnectionException $e) { $failure['db']++; \cmdman\Std::println_danger(' ' . $class_name . ' Failure, ' . $e->getMessage()); } catch (\Exception $e) { $failure['db']++; \cmdman\Std::println_warning(' ' . $class_name . ' Failure, ' . $e->getMessage()); } } \cmdman\Std::println(); \cmdman\Std::println_info('Entry:'); foreach (\ebi\Util::ls(getcwd()) as $f) { $src = file_get_contents($f->getPathname()); if (strpos($src, '\\ebi\\Flow::app(') !== false) { $map = \ebi\Flow::get_map($f->getPathname()); $entry = str_replace(getcwd(), '', $f->getPathname()); foreach ($map['patterns'] as $p) { if (array_key_exists('action', $p) && is_string($p['action'])) { try { list($c, $m) = explode('::', $p['action']); $mr = new \ReflectionMethod(\ebi\Util::get_class_name($c), $m); \cmdman\Std::println_success($entry . ' ' . $p['name'] . ' OK'); } catch (\ReflectionException $e) { $failure['entry']++; \cmdman\Std::println_danger($entry . ' ' . $p['name'] . ' Failure'); }
file_put_contents($settings_file, '<?php' . PHP_EOL . 'define(\'APPMODE\',\'' . $mode . '\');' . PHP_EOL . 'define(\'COMMONDIR\',\'' . $cmndir . '\');' . PHP_EOL); \cmdman\Std::println_success('Written: ' . realpath($settings_file)); if (!is_file($f = $cmndir . '/' . $mode . '.php')) { \ebi\Util::file_write($f, <<<'__SRC__' <?php \ebi\Conf::set([ ]); __SRC__ ); \cmdman\Std::println_success('Written: ' . realpath($f)); } if ($mode != $appmode) { \cmdman\Std::println_info('Application mode changed.'); return; } else { \cmdman\Std::println_info('Application mode is `' . $mode . '`'); } if (!is_file($f = $path . '/bootstrap.php')) { $autoload_file = ''; if (class_exists('Composer\\Autoload\\ClassLoader')) { $r = new \ReflectionClass('Composer\\Autoload\\ClassLoader'); $composer_dir = dirname($r->getFileName()); if (is_file($bf = realpath(dirname($composer_dir) . '/autoload.php'))) { $autoload_file = str_replace(str_replace("\\", '/', getcwd()) . '/', '', str_replace("\\", '/', $bf)); } } else { foreach (\ebi\Util::ls($path, true, '/ebi\\.phar$/') as $p) { $autoload_file = str_replace(str_replace("\\", '/', getcwd()) . '/', '', str_replace("\\", '/', $p)); break; } }