Exemple #1
0
 /**
  * Esegue una migrazione
  *
  * @param string $filename
  * @param bool $write (default true)
  * @return bool
  */
 public function exec($filename, $write = true)
 {
     if (!file_exists($this->directory->getPath() . '/' . $filename)) {
         throw new Exception("Il file {$filename} non esiste");
     }
     $file = new FileSystem($this->directory->getPath() . '/' . $filename);
     // if(! $file->exists()) {
     //     throw new Exception("Il file $filename non esiste");
     // }
     $fileInfo = $file->getInfo();
     try {
         if ($fileInfo['type'] == Migration::FILETYPE_SQL) {
             $statements = self::parseStatements($file->read());
             foreach ($statements as $stmt) {
                 $res = $this->sqlDriver->executeQuery($stmt);
             }
             $resp = true;
         } elseif ($fileInfo['type'] == Migration::FILETYPE_PHP) {
             $className = 'Mosaicoon\\Database\\Migration\\Migrations\\' . $fileInfo['name'];
             $obj = new $className();
             $obj->run();
             $resp = true;
         }
     } catch (\Exception $e) {
         throw new \Exception("Error on file {$filename}: " . $e->getMessage());
     }
     if ($write) {
         $this->datastore->storeMigratedFile($filename, null);
     }
     return $resp;
 }
Exemple #2
0
 /**
  * Verifica se il nome della classe è già stato usato per un'altra migrazione
  *
  * @param string $className
  * @return bool
  */
 private static function isDuplicateClass($className)
 {
     $dir = new FileSystem(self::$directory);
     foreach ($dir->read() as $file) {
         $info = @PathResolver::decode($file);
         if ($info['name'] == $className) {
             return true;
         }
     }
     return false;
 }