/** * Run DB migrations from migration .sql files * @return int count of applied migrations */ public function runMigrations() { // Check we havy any if (!file_exists(DIR_MIGRATIONS)) { return 0; } // Check we have DB structure and any migration applied $migrated_files = []; if (SQL::getTables()) { // Have DB already? $migrations = new MigrationEntityRepository(); $migrated_files = $migrations->getPairs('filename', 'filename'); } $existing_files = FileSystem::scanDirs(DIR_MIGRATIONS); if (!$existing_files) { return 0; } $to_migrate = []; // Filters migrations that are already done foreach ($existing_files as $file) { if (isset($migrated_files[$file['name']])) { continue; } $to_migrate[] = $file['name']; } // Run new migrations foreach ($to_migrate as $file) { $this->runMigrationFile($file); $this->setMigrationFileAsCompleted($file); } return count($to_migrate); }
/** * @param string $key * @return bool */ public function delete($key) { if (!FileSystem::checkFileName($key)) { return false; } $path = $this->getPathToFile($key); if (!$path) { return false; } $file = $path . $key; if (!is_file($file)) { return false; } unlink($file); // Delete file // If no more files in folder with same hash - remove all folder if (!count(FileSystem::scanDirs($path))) { FileSystem::remdir($path); } return true; }