src/Common/Console/Command/Database/Migrate.php
protected function determineModuleState($sModuleName, $sMigrationsPath): ?\stdClass
    {
        $oModule = (object) [
            'name'  => $sModuleName,
            'start' => null,
            'end'   => null,
        ];

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

        //  Work out if the module needs migrated and if so between what and what
        $aDirMap = $this->mapDir($sMigrationsPath);

        if (!empty($aDirMap)) {

            //  Work out all the files we have and get their index
            $aMigrations = [];
            foreach ($aDirMap as $dir) {
                $aMigrations[$dir['path']] = [
                    'index' => $dir['index'],
                ];
            }

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

            //  Work out the current version
            $sSql    = "SELECT `version` FROM `" . NAILS_DB_PREFIX . "migration` WHERE `module` = '$sModuleName';";
            $oResult = $this->oDb->query($sSql);

            if ($oResult->rowCount() === 0) {

                //  Add a row for the module
                $sSql = "INSERT INTO `" . NAILS_DB_PREFIX . "migration` (`module`, `version`) VALUES ('$sModuleName', NULL);";
                $this->oDb->query($sSql);

                $iCurrentVersion = null;

            } else {
                $iCurrentVersion = $oResult->fetch(\PDO::FETCH_OBJ)->version;
                $iCurrentVersion = is_null($iCurrentVersion) ? null : (int) $iCurrentVersion;
            }

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

            //  Define the variable
            $aLastMigration = end($aMigrations);
            $oModule->start = $iCurrentVersion;
            $oModule->end   = $aLastMigration['index'];
        }

        return $oModule->start === $oModule->end ? null : $oModule;
    }
protected function determineModuleState($sModuleName, $sMigrationsPath): ?\stdClass
    {
        $oModule = (object) [
            'name'  => $sModuleName,
            'start' => null,
            'end'   => null,
        ];

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

        //  Work out if the module needs migrated and if so between what and what
        $aDirMap = $this->mapDir($sMigrationsPath);

        if (!empty($aDirMap)) {

            //  Work out all the files we have and get their index
            $aMigrations = [];
            foreach ($aDirMap as $dir) {
                $aMigrations[$dir['path']] = [
                    'index' => $dir['index'],
                ];
            }

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

            //  Work out the current version
            $sSql    = "SELECT `version` FROM `" . NAILS_DB_PREFIX . "migration` WHERE `module` = '$sModuleName';";
            $oResult = $this->oDb->query($sSql);

            if ($oResult->rowCount() === 0) {

                //  Add a row for the module
                $sSql = "INSERT INTO `" . NAILS_DB_PREFIX . "migration` (`module`, `version`) VALUES ('$sModuleName', NULL);";
                $this->oDb->query($sSql);

                $iCurrentVersion = null;

            } else {
                $iCurrentVersion = $oResult->fetch(\PDO::FETCH_OBJ)->version;
                $iCurrentVersion = is_null($iCurrentVersion) ? null : (int) $iCurrentVersion;
            }

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

            //  Define the variable
            $aLastMigration = end($aMigrations);
            $oModule->start = $iCurrentVersion;
            $oModule->end   = $aLastMigration['index'];
        }

        return $oModule->start === $oModule->end ? null : $oModule;
    }
protected function determineModuleState ( $ sModuleName , $ sMigrationsPath ) : ? \ stdClass { $ oModule = ( object ) [ 'name' => $ sModuleName , 'start' => null , 'end' => null , ] ; // -------------------------------------------------------------------------- //  Work out if the module needs migrated and if so between what and what $ aDirMap = $ this -> mapDir ( $ sMigrationsPath ) ; if ( ! empty ( $ aDirMap ) ) { //  Work out all the files we have and get their index $ aMigrations = [ ] ; foreach ( $ aDirMap as $ dir ) { $ aMigrations [ $ dir [ 'path' ] ] = [ 'index' => $ dir [ 'index' ] , ] ; } // -------------------------------------------------------------------------- //  Work out the current version $ sSql = "SELECT `version` FROM `" . NAILS_DB_PREFIX . "migration` WHERE `module` = '$sModuleName';" ; $ oResult = $ this -> oDb -> query ( $ sSql ) ; if ( $ oResult -> rowCount ( ) === 0 ) { //  Add a row for the module $ sSql = "INSERT INTO `" . NAILS_DB_PREFIX . "migration` (`module`, `version`) VALUES ('$sModuleName', NULL);" ; $ this -> oDb -> query ( $ sSql ) ; $ iCurrentVersion = null ; } else { $ iCurrentVersion = $ oResult -> fetch ( \ PDO :: FETCH_OBJ ) -> version ; $ iCurrentVersion = is_null ( $ iCurrentVersion ) ? null : ( int ) $ iCurrentVersion ; } // -------------------------------------------------------------------------- //  Define the variable $ aLastMigration = end ( $ aMigrations ) ; $ oModule -> start = $ iCurrentVersion ; $ oModule -> end = $ aLastMigration [ 'index' ] ; } return $ oModule -> start === $ oModule -> end ? null : $ oModule ; }
Determines whether or not the module needs to migration, and if so between what versions

@param string $sModuleName     The module's name
@param string $sMigrationsPath The module's path

@return \stdClass|null stdClass when migration needed, null when not needed
Determines whether or not the module needs to migration and if so between what versions