src/Common/Console/Command/Database/Migrate.php
protected function doMigration($oModule): bool
    {
        $oOutput = $this->oOutput;

        // --------------------------------------------------------------------------

        //  Map the directory and fetch only the files we need
        $sPath   = $oModule->name == 'APP' ? 'application/migrations/' : 'vendor/' . $oModule->name . '/migrations/';
        $aDirMap = $this->mapDir($sPath);

        //  Set the current version to -1 if null so migrations with a zero index are picked up
        $iCurrent = is_null($oModule->start) ? -1 : $oModule->start;

        //  Go through all the migrations, skip any which have already been executed
        foreach ($aDirMap as $aMigration) {
            if ($aMigration['index'] > $iCurrent) {
                if (!$this->executeMigration($oModule, $aMigration)) {
                    return false;
                }
            }

            //  Mark this migration as complete
            $sSql    = "UPDATE `" . NAILS_DB_PREFIX . "migration` SET `version` = " . $aMigration['index'] . " WHERE `module` = '" . $oModule->name . "'";
            $oResult = $this->oDb->query($sSql);
        }

        if (!$oResult) {

            // Error updating migration record
            $oOutput->writeln('');
            $oOutput->writeln('');
            $oOutput->writeln('<error>ERROR</error>: Failed to update migration record for <info>' . $oModule->name . '</info>.');

            return false;
        }

        return true;
    }
protected function doMigration($oModule): bool
    {
        $oOutput = $this->oOutput;

        // --------------------------------------------------------------------------

        //  Map the directory and fetch only the files we need
        $sPath   = $oModule->name == 'APP' ? 'application/migrations/' : 'vendor/' . $oModule->name . '/migrations/';
        $aDirMap = $this->mapDir($sPath);

        //  Set the current version to -1 if null so migrations with a zero index are picked up
        $iCurrent = is_null($oModule->start) ? -1 : $oModule->start;

        //  Go through all the migrations, skip any which have already been executed
        foreach ($aDirMap as $aMigration) {
            if ($aMigration['index'] > $iCurrent) {
                if (!$this->executeMigration($oModule, $aMigration)) {
                    return false;
                }
            }

            //  Mark this migration as complete
            $sSql    = "UPDATE `" . NAILS_DB_PREFIX . "migration` SET `version` = " . $aMigration['index'] . " WHERE `module` = '" . $oModule->name . "'";
            $oResult = $this->oDb->query($sSql);
        }

        if (!$oResult) {

            // Error updating migration record
            $oOutput->writeln('');
            $oOutput->writeln('');
            $oOutput->writeln('<error>ERROR</error>: Failed to update migration record for <info>' . $oModule->name . '</info>.');

            return false;
        }

        return true;
    }
protected function doMigration ( $ oModule ) : bool { $ oOutput = $ this -> oOutput ; // -------------------------------------------------------------------------- //  Map the directory and fetch only the files we need $ sPath = $ oModule -> name == 'APP' ? 'application/migrations/' : 'vendor/' . $ oModule -> name . '/migrations/' ; $ aDirMap = $ this -> mapDir ( $ sPath ) ; //  Set the current version to -1 if null so migrations with a zero index are picked up $ iCurrent = is_null ( $ oModule -> start ) ? - 1 : $ oModule -> start ; //  Go through all the migrations, skip any which have already been executed foreach ( $ aDirMap as $ aMigration ) { if ( $ aMigration [ 'index' ] > $ iCurrent ) { if ( ! $ this -> executeMigration ( $ oModule , $ aMigration ) ) { return false ; } } //  Mark this migration as complete $ sSql = "UPDATE `" . NAILS_DB_PREFIX . "migration` SET `version` = " . $ aMigration [ 'index' ] . " WHERE `module` = '" . $ oModule -> name . "'" ; $ oResult = $ this -> oDb -> query ( $ sSql ) ; } if ( ! $ oResult ) { // Error updating migration record $ oOutput -> writeln ( '' ) ; $ oOutput -> writeln ( '' ) ; $ oOutput -> writeln ( '<error>ERROR</error>: Failed to update migration record for <info>' . $ oModule -> name . '</info>.' ) ; return false ; } return true ; }
Executes a migration

@param  \stdClass $oModule The migration details object

@return boolean
Executes a migration