src/Common/Console/Command/Database/Migrate.php
private function executeMigration($oModule, $aMigration): bool
    {
        $oOutput = $this->oOutput;

        require_once $aMigration['path'];

        //  Generate the expected class name, i.e., "vendor-name/package-name" -> VendorName\PackageName"
        $sPattern    = '[^a-zA-Z0-9' . preg_quote(DIRECTORY_SEPARATOR, '/\-') . ']';
        $sModuleName = strtolower($oModule->name);
        $sModuleName = preg_replace('/' . $sPattern . '/', ' ', $sModuleName);
        $sModuleName = str_replace(DIRECTORY_SEPARATOR, ' ' . DIRECTORY_SEPARATOR . ' ', $sModuleName);
        $sModuleName = ucwords($sModuleName);
        $sModuleName = str_replace(' ', '', $sModuleName);
        $sModuleName = str_replace(DIRECTORY_SEPARATOR, '\\', $sModuleName);

        $sClassName = 'Nails\Database\Migration\\' . $sModuleName . '\Migration' . $aMigration['index'];

        if (class_exists($sClassName)) {

            $oMigration = new $sClassName();

            if (is_subclass_of($oMigration, 'Nails\Common\Console\Migrate\Base')) {

                try {
                    $oMigration->execute();
                } catch (\Exception $e) {
                    $oOutput->writeln('');
                    $oOutput->writeln('');
                    $oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" failed:');
                    $oOutput->writeln('<error>ERROR</error>: #' . $e->getCode() . ' - ' . $e->getMessage());
                    $oOutput->writeln('<error>ERROR</error>: Failed Query: #' . $oMigration->getQueryCount());
                    $oOutput->writeln('<error>ERROR</error>: Failed Query: ' . $oMigration->getLastQuery());
                    return false;
                }

            } else {

                $oOutput->writeln('');
                $oOutput->writeln('');
                $oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" is badly configured.');
                $oOutput->writeln('<error>ERROR</error>: Should be a sub-class of "Nails\Common\Console\Migrate\Base".');
                return false;
            }

            unset($oMigration);

        } else {

            $oOutput->writeln('');
            $oOutput->writeln('');
            $oOutput->writeln('<error>ERROR</error>: Class "' . $sClassName . '" does not exist.');
            $oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" is badly configured.');
            return false;
        }

        return true;
    }
private function executeMigration($oModule, $aMigration): bool
    {
        $oOutput = $this->oOutput;

        require_once $aMigration['path'];

        //  Generate the expected class name, i.e., "vendor-name/package-name" -> VendorName\PackageName"
        $sPattern    = '[^a-zA-Z0-9' . preg_quote(DIRECTORY_SEPARATOR, '/\-') . ']';
        $sModuleName = strtolower($oModule->name);
        $sModuleName = preg_replace('/' . $sPattern . '/', ' ', $sModuleName);
        $sModuleName = str_replace(DIRECTORY_SEPARATOR, ' ' . DIRECTORY_SEPARATOR . ' ', $sModuleName);
        $sModuleName = ucwords($sModuleName);
        $sModuleName = str_replace(' ', '', $sModuleName);
        $sModuleName = str_replace(DIRECTORY_SEPARATOR, '\\', $sModuleName);

        $sClassName = 'Nails\Database\Migration\\' . $sModuleName . '\Migration' . $aMigration['index'];

        if (class_exists($sClassName)) {

            $oMigration = new $sClassName();

            if (is_subclass_of($oMigration, 'Nails\Common\Console\Migrate\Base')) {

                try {
                    $oMigration->execute();
                } catch (\Exception $e) {
                    $oOutput->writeln('');
                    $oOutput->writeln('');
                    $oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" failed:');
                    $oOutput->writeln('<error>ERROR</error>: #' . $e->getCode() . ' - ' . $e->getMessage());
                    $oOutput->writeln('<error>ERROR</error>: Failed Query: #' . $oMigration->getQueryCount());
                    $oOutput->writeln('<error>ERROR</error>: Failed Query: ' . $oMigration->getLastQuery());
                    return false;
                }

            } else {

                $oOutput->writeln('');
                $oOutput->writeln('');
                $oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" is badly configured.');
                $oOutput->writeln('<error>ERROR</error>: Should be a sub-class of "Nails\Common\Console\Migrate\Base".');
                return false;
            }

            unset($oMigration);

        } else {

            $oOutput->writeln('');
            $oOutput->writeln('');
            $oOutput->writeln('<error>ERROR</error>: Class "' . $sClassName . '" does not exist.');
            $oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" is badly configured.');
            return false;
        }

        return true;
    }
private function executeMigration ( $ oModule , $ aMigration ) : bool { $ oOutput = $ this -> oOutput ; require_once $ aMigration [ 'path' ] ; //  Generate the expected class name, i.e., "vendor-name/package-name" -> VendorName\PackageName" $ sPattern = '[^a-zA-Z0-9' . preg_quote ( DIRECTORY_SEPARATOR , '/\-' ) . ']' ; $ sModuleName = strtolower ( $ oModule -> name ) ; $ sModuleName = preg_replace ( '/' . $ sPattern . '/' , ' ' , $ sModuleName ) ; $ sModuleName = str_replace ( DIRECTORY_SEPARATOR , ' ' . DIRECTORY_SEPARATOR . ' ' , $ sModuleName ) ; $ sModuleName = ucwords ( $ sModuleName ) ; $ sModuleName = str_replace ( ' ' , '' , $ sModuleName ) ; $ sModuleName = str_replace ( DIRECTORY_SEPARATOR , '\\' , $ sModuleName ) ; $ sClassName = 'Nails\Database\Migration\\' . $ sModuleName . '\Migration' . $ aMigration [ 'index' ] ; if ( class_exists ( $ sClassName ) ) { $ oMigration = new $ sClassName ( ) ; if ( is_subclass_of ( $ oMigration , 'Nails\Common\Console\Migrate\Base' ) ) { try { $ oMigration -> execute ( ) ; } catch ( \ Exception $ e ) { $ oOutput -> writeln ( '' ) ; $ oOutput -> writeln ( '' ) ; $ oOutput -> writeln ( '<error>ERROR</error>: Migration at "' . $ aMigration [ 'path' ] . '" failed:' ) ; $ oOutput -> writeln ( '<error>ERROR</error>: #' . $ e -> getCode ( ) . ' - ' . $ e -> getMessage ( ) ) ; $ oOutput -> writeln ( '<error>ERROR</error>: Failed Query: #' . $ oMigration -> getQueryCount ( ) ) ; $ oOutput -> writeln ( '<error>ERROR</error>: Failed Query: ' . $ oMigration -> getLastQuery ( ) ) ; return false ; } } else { $ oOutput -> writeln ( '' ) ; $ oOutput -> writeln ( '' ) ; $ oOutput -> writeln ( '<error>ERROR</error>: Migration at "' . $ aMigration [ 'path' ] . '" is badly configured.' ) ; $ oOutput -> writeln ( '<error>ERROR</error>: Should be a sub-class of "Nails\Common\Console\Migrate\Base".' ) ; return false ; } unset ( $ oMigration ) ; } else { $ oOutput -> writeln ( '' ) ; $ oOutput -> writeln ( '' ) ; $ oOutput -> writeln ( '<error>ERROR</error>: Class "' . $ sClassName . '" does not exist.' ) ; $ oOutput -> writeln ( '<error>ERROR</error>: Migration at "' . $ aMigration [ 'path' ] . '" is badly configured.' ) ; return false ; } return true ; }
Executes an individual migration

@param  object $oModule    The module being migrated
@param  array  $aMigration The migration details

@return boolean
Executes an individual migration