/** * Migrate up * * @access public */ public function up() { $db = Database::get(); $table = File::trait_get_database_table(); $tables = $db->get_column("SHOW TABLES LIKE '" . $table . "'", []); if (count($tables) == 0) { $db->query("\n\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $table . "` (\n\t\t\t\t `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t `name` varchar(128) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t `unique_name` varchar(128) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t `md5sum` varchar(128) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t `mime_type` varchar(128) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t `size` int(11) NOT NULL,\n\t\t\t\t `created` datetime NOT NULL,\n\t\t\t\t `deleted` datetime NOT NULL,\n\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t\t", []); } }
/** * Migrate up * * @access public */ public function up() { $table = File::trait_get_database_table(); $db = Database::get(); $ids = $db->get_column('SELECT id FROM ' . $table, []); foreach ($ids as $id) { $file = File::get_by_id($id); $old_path = $this->get_old_path($file); if (!file_exists($old_path)) { continue; } $new_path = $file->get_path(); // create directory if not exist $pathinfo = pathinfo($new_path); if (!is_dir($pathinfo['dirname'])) { mkdir($pathinfo['dirname'], 0755, true); } rename($old_path, $new_path); } /** * Run this to cleanup empty directories */ // echo 'find ' . $path . ' -type d -empty -delete'; }