/** * Migrate the database up to the current migration * This method starts by replication the index.php file * of CodeIgniter. * * @access private * @return void * @author Aziz Light **/ private function current($rollback = FALSE) { if ($rollback === FALSE) { $migration_number = MigrationHelpers::get_latest_migration_number($this->location); MigrationHelpers::add_migration_number_to_config_file($this->location, $migration_number); } else { define('MIGRATION_ROLLBACK', 'TRUE'); } foreach ($_SERVER['argv'] as $index => $value) { if ($index === 0) { continue; } else { array_pop($_SERVER['argv']); } } $_SERVER['argv'][] = "migrate"; // --------------------------------------------------------------------- $system_path = $this->system_folder; $generate_config = parse_ini_file(BASE_PATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'generate.ini'); $application_folder = $generate_config['application_folder']; $view_folder = ''; unset($this->system_folder, $generate_config); if (($_temp = realpath($system_path)) !== FALSE) { $system_path = $_temp . '/'; } else { $system_path = rtrim($system_path, '/') . '/'; } if (!is_dir($system_path)) { header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); exit('Your system folder path does not appear to be set correctly. Please open the following file and correct this: ' . pathinfo(__FILE__, PATHINFO_BASENAME)); } define('SELF', pathinfo(getcwd() . '/index.php', PATHINFO_BASENAME)); define('BASEPATH', str_replace('\\', '/', $system_path)); define('FCPATH', getcwd()); define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/')); if (is_dir($application_folder)) { if (($_temp = realpath($application_folder)) !== FALSE) { $application_folder = $_temp; } define('APPPATH', $application_folder . '/'); } else { if (!is_dir(BASEPATH . $application_folder . '/')) { header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); exit('Your application folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF); } define('APPPATH', BASEPATH . $application_folder . '/'); } if (!is_dir($view_folder)) { if (!empty($view_folder) && is_dir(APPPATH . $view_folder . '/')) { $view_folder = APPPATH . $view_folder; } elseif (!is_dir(APPPATH . 'views/')) { header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); exit('Your view folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF); } else { $view_folder = APPPATH . 'views'; } } if (($_temp = realpath($view_folder)) !== FALSE) { $view_folder = realpath($view_folder) . '/'; } else { $view_folder = rtrim($view_folder, '/') . '/'; } define('VIEWPATH', $view_folder); require_once BASEPATH . 'core/CodeIgniter.php'; }
/** * Create a migration file * * @access private * @return void * @author Aziz Light **/ private function migration() { $location = $this->args['location'] . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR; if (!is_dir($location)) { mkdir($location); } $backtrace = debug_backtrace(); $calling_function = $backtrace[1]['function']; if ($calling_function === "model") { $args = array('class_name' => 'Migration_Add_' . Inflector::pluralize($this->args['name']), 'table_name' => Inflector::pluralize(strtolower($this->args['name'])), 'filename' => 'add_' . Inflector::pluralize(ApplicationHelpers::underscorify($this->args['name'])) . '.php', 'application_folder' => $this->args['application_folder'], 'parent_class' => $this->args['parent_migration'], 'extra' => $this->extra); $template_name = 'migration'; } else { $args = array('class_name' => 'Migration_' . $this->args['name'], 'table_name' => $this->get_table_name_out_of_migration_name(), 'filename' => $this->args['filename'], 'application_folder' => $this->args['application_folder'], 'parent_class' => $this->args['parent_migration'], 'extra' => $this->extra); $template_name = 'empty_migration'; } $template = new TemplateScanner($template_name, $args); $migration = $template->parse(); $migration_number = MigrationHelpers::get_migration_number($this->args['location']); $filename = $location . $migration_number . '_' . $args['filename']; $potential_duplicate_migration_filename = MigrationHelpers::decrement_migration_number($migration_number) . '_' . $args['filename']; $potential_duplicate_migration = $location . $potential_duplicate_migration_filename; $message = "\t"; if (file_exists($potential_duplicate_migration)) { $message .= 'Migration already exists : '; if (php_uname("s") !== "Windows NT") { $message = ApplicationHelpers::colorize($message, 'light_blue'); } $message .= $this->args['application_folder'] . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR . $potential_duplicate_migration_filename; } else { if (file_put_contents($filename, $migration) && MigrationHelpers::add_migration_number_to_config_file($this->args['location'], $migration_number)) { $message .= 'Created Migration: '; if (php_uname("s") !== "Windows NT") { $message = ApplicationHelpers::colorize($message, 'green'); } $message .= $this->args['application_folder'] . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR . $migration_number . '_' . $args['filename']; } else { $message .= 'Unable to create migration: '; if (php_uname("s") !== "Windows NT") { $message = ApplicationHelpers::colorize($message, 'red'); } $message .= $this->args['application_folder'] . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR . $migration_number . '_' . $this->args['filename']; } } fwrite(STDOUT, $message . PHP_EOL); return; }