define('FLOW_PATH_FLOW', str_replace('//', '/', str_replace('\\', '/', realpath(__DIR__ . '/../') . '/')));
define('FLOW_PATH_ROOT', str_replace('//', '/', str_replace('\\', '/', realpath(__DIR__ . '/../../../../') . '/')));
define('FLOW_PATH_WEB', FLOW_PATH_ROOT . 'Web/');
define('FLOW_PATH_CONFIGURATION', FLOW_PATH_ROOT . 'Configuration/');
define('FLOW_PATH_DATA', FLOW_PATH_ROOT . 'Data/');
define('MAXIMUM_LINE_LENGTH', 84);
define('STYLE_DEFAULT', 0);
define('STYLE_ERROR', 31);
define('STYLE_WARNING', 33);
define('STYLE_SUCCESS', 32);
if (flagIsSet('packages-path')) {
    define('FLOW_PATH_PACKAGES', getFlagValue('packages-path'));
} else {
    define('FLOW_PATH_PACKAGES', FLOW_PATH_ROOT . 'Packages/');
}
if (\Neos\Flow\Core\Migrations\Git::isGitAvailable() === false) {
    outputLine('No executable git binary found, exiting.');
    exit(255);
}
$migrationsManager = new Manager();
$packageKey = getFlagValue('package-key');
$versionNumber = null;
if (flagIsSet('version')) {
    if (preg_match('/[0-9]{12,14}/', getFlagValue('version'), $matches) !== 1) {
        outputLine('EXCEPTION: invalid version "%s" specified, please provide the 12 or 14 digit timestamp of the version you want to target.', array(getFlagValue('version')), 0, STYLE_ERROR);
        exit(255);
    }
    $versionNumber = $matches[0];
    // see https://jira.neos.io/browse/FLOW-110
    if (strlen($versionNumber) === 12) {
        $versionNumber .= '00';
 /**
  * Applies all registered moveFile operations.
  *
  * @return void
  */
 protected function applyFileOperations()
 {
     foreach ($this->operations['moveFile'] as $operation) {
         $oldPath = Files::concatenatePaths(array($this->targetPackageData['path'] . '/' . $operation[0]));
         $newPath = Files::concatenatePaths(array($this->targetPackageData['path'] . '/' . $operation[1]));
         if (substr($oldPath, -1) === '*') {
             $oldPath = substr($oldPath, 0, -1);
             if (!file_exists($oldPath)) {
                 continue;
             }
             if (!file_exists($newPath)) {
                 Files::createDirectoryRecursively($newPath);
             }
             if (!is_dir($newPath)) {
                 continue;
             }
             foreach (Files::getRecursiveDirectoryGenerator($this->targetPackageData['path'], null, true) as $pathAndFilename) {
                 if (substr_compare($pathAndFilename, $oldPath, 0, strlen($oldPath)) === 0) {
                     $relativePathAndFilename = substr($pathAndFilename, strlen($oldPath));
                     if (!is_dir(dirname(Files::concatenatePaths(array($newPath, $relativePathAndFilename))))) {
                         Files::createDirectoryRecursively(dirname(Files::concatenatePaths(array($newPath, $relativePathAndFilename))));
                     }
                     Git::move($pathAndFilename, Files::concatenatePaths(array($newPath, $relativePathAndFilename)));
                 }
             }
         } else {
             $oldPath = Files::concatenatePaths(array($this->targetPackageData['path'] . '/' . $operation[0]));
             $newPath = Files::concatenatePaths(array($this->targetPackageData['path'] . '/' . $operation[1]));
             Git::move($oldPath, $newPath);
         }
     }
     foreach ($this->operations['deleteFile'] as $operation) {
         $filename = Files::concatenatePaths(array($this->targetPackageData['path'] . '/' . $operation[0]));
         if (file_exists($filename)) {
             Git::remove($filename);
         }
     }
 }
 /**
  * Commit changes done to the package described by $packageData. The migration
  * that was did the changes is given with $versionNumber and $versionPackageKey
  * and will be recorded in the commit message.
  *
  * @param AbstractMigration $migration
  * @param string $commitMessageNotice
  * @return string
  */
 protected function commitMigration(AbstractMigration $migration, $commitMessageNotice = null)
 {
     $migrationIdentifier = $migration->getIdentifier();
     $commitMessageSubject = sprintf('TASK: Apply migration %s', $migrationIdentifier);
     if (!Git::isWorkingCopyRoot($this->currentPackageData['path'])) {
         $commitMessageSubject .= sprintf(' to package "%s"', $this->currentPackageData['packageKey']);
     }
     $commitMessage = $commitMessageSubject . chr(10) . chr(10);
     $description = $migration->getDescription();
     if ($description !== null) {
         $commitMessage .= wordwrap($description, 72);
     } else {
         $commitMessage .= wordwrap(sprintf('This commit contains the result of applying migration %s to this package.', $migrationIdentifier), 72);
     }
     if ($commitMessageNotice !== null) {
         $commitMessage .= chr(10) . chr(10) . wordwrap($commitMessageNotice, 72) . chr(10) . chr(10);
     }
     list($returnCode, $output) = Git::commitAll($this->currentPackageData['path'], $commitMessage);
     if ($returnCode === 0) {
         return '    ' . implode(PHP_EOL . '    ', $output) . PHP_EOL;
     } else {
         return '    No changes were committed.' . PHP_EOL;
     }
 }