Example #1
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;
 }
Example #2
0
 /**
  * Esegue le migrations
  *
  * @param bool $useTransactions (default false)
  * @param bool $justSql (default false)
  * @return array
  */
 public function executeAll($useTransactions = false, $justSql = false)
 {
     if (empty($this->datastore)) {
         throw new \Exception("Interfaccia Db non valida");
     }
     $dirFiles = $this->directory->read();
     $migratedFiles = $this->datastore->getMigratedFiles();
     //filtra i file da eseguire
     $files = array_filter($dirFiles, function ($file) use($migratedFiles, $justSql) {
         $item = @PathResolver::decode($file);
         $permittedFiles = !$justSql ? [Migration::FILETYPE_SQL, Migration::FILETYPE_PHP] : [Migration::FILETYPE_SQL];
         return in_array(@$item['type'], $permittedFiles) && !in_array($file, $migratedFiles);
     });
     //ordina i files per data di creazione in modo crescente (ASC)
     usort($files, function ($a, $b) {
         return @PathResolver::decode($a)['time'] < @PathResolver::decode($b)['time'] ? -1 : 1;
     });
     foreach ($files as $file) {
         $this->exec($file);
     }
     return $files;
 }
Example #3
0
 /**
  * Ritorna le informazioni del file
  *
  * @return array
  */
 public function getInfo()
 {
     return PathResolver::decode($this->path);
 }
Example #4
0
 /**
  * Ritorna un template
  *
  * @param string $filename
  * @param string $date
  * @param string $author (optional)
  * @param string $description (optional)
  * @return string
  */
 public static function getTemplate($filename, $date, $author = null, $description = null)
 {
     $info = PathResolver::decode($filename);
     $className = $info['name'];
     return "<?php\n\nnamespace Mosaicoon\\Database\\Migration\\Migrations;\n\nuse Mosaicoon\\Database\\Migration\\Migrations\\AbstractMigrator;\nuse Mosaicoon\\Database\\Migration\\Migrations\\MigratorInterface;\n\n/**\n * Creato in {$date}\n * {$description}\n *\n * @author {$author}\n **/\nclass {$className} extends AbstractMigrator implements MigratorInterface\n{\n    //Never look back...\n    public function run()\n    {\n        //Scrivi il tuo codice qui, gioia.\n    }\n}\n\n";
 }