Neos\Flow\Persistence\Doctrine\Migrations\Version20141118174722::postUp PHP Метод

postUp() публичный Метод

Move resource files to the new locations and adjust records.
public postUp ( Doctrine\DBAL\Schema\Schema $schema ) : void
$schema Doctrine\DBAL\Schema\Schema
Результат void
    public function postUp(Schema $schema)
    {
        $resourcesResult = $this->connection->executeQuery('SELECT persistence_object_identifier, sha1, filename FROM typo3_flow_resource_resource');
        while ($resourceInfo = $resourcesResult->fetch(\PDO::FETCH_ASSOC)) {
            $resourcePathAndFilename = FLOW_PATH_DATA . 'Persistent/Resources/' . $resourceInfo['sha1'];
            $newResourcePathAndFilename = FLOW_PATH_DATA . 'Persistent/Resources/' . $resourceInfo['sha1'][0] . '/' . $resourceInfo['sha1'][1] . '/' . $resourceInfo['sha1'][2] . '/' . $resourceInfo['sha1'][3] . '/' . $resourceInfo['sha1'];
            $mediaType = MediaTypes::getMediaTypeFromFilename($resourceInfo['filename']);
            if (file_exists($resourcePathAndFilename)) {
                $md5 = md5_file($resourcePathAndFilename);
                $filesize = filesize($resourcePathAndFilename);
                if (!file_exists(dirname($newResourcePathAndFilename))) {
                    Files::createDirectoryRecursively(dirname($newResourcePathAndFilename));
                }
                $result = @rename($resourcePathAndFilename, $newResourcePathAndFilename);
            } elseif (file_exists($newResourcePathAndFilename)) {
                $md5 = md5_file($newResourcePathAndFilename);
                $filesize = filesize($newResourcePathAndFilename);
                $result = true;
            } else {
                $this->write(sprintf('Error while migrating database for the new resource management: the resource file "%s" (original filename: %s) was not found, but the resource object with uuid %s needs this file.', $resourcePathAndFilename, $resourceInfo['filename'], $resourceInfo['persistence_object_identifier']));
                continue;
            }
            $this->connection->executeUpdate('UPDATE typo3_flow_resource_resource SET collectionname = ?, mediatype = ?, md5 = ?, filesize = ? WHERE persistence_object_identifier = ?', array('persistent', $mediaType, $md5, $filesize, $resourceInfo['persistence_object_identifier']));
            if ($result === false) {
                $this->write(sprintf('Could not move the data file of resource "%s" from its legacy location at %s to the correct location %s.', $resourceInfo['sha1'], $resourcePathAndFilename, $newResourcePathAndFilename));
            }
        }
        $this->connection->exec('ALTER TABLE typo3_flow_resource_resource ALTER md5 SET NOT NULL');
        $this->connection->exec('ALTER TABLE typo3_flow_resource_resource ALTER collectionname SET NOT NULL');
        $this->connection->exec('ALTER TABLE typo3_flow_resource_resource ALTER mediatype SET NOT NULL');
        $this->connection->exec('ALTER TABLE typo3_flow_resource_resource ALTER filesize SET NOT NULL');
    }
Version20141118174722