/**
  * 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;
     }
 }
 /**
  * Apply the given migration to the package and commit the result.
  *
  * @param string $packageKey
  * @param array $packageData
  * @param AbstractMigration $migration
  * @return void
  * @throws \RuntimeException
  */
 protected function migratePackage($packageKey, array $packageData, AbstractMigration $migration)
 {
     if (Git::isWorkingCopyClean($packageData['path'])) {
         if (Git::hasMigrationApplied($packageData['path'], $migration->getIdentifier())) {
             echo '  Skipping ' . $packageKey . ', the migration is already applied.' . PHP_EOL;
         } else {
             echo '  Migrating ' . $packageKey . PHP_EOL;
             try {
                 $migration->prepare($this->packagesData[$packageKey]);
                 $migration->up();
                 $migration->execute();
                 echo Git::commitMigration($packageData['path'], $migration->getIdentifier());
             } catch (\Exception $exception) {
                 throw new \RuntimeException('Applying migration "' . $migration->getIdentifier() . '" to "' . $packageKey . '" failed.', 0, $exception);
             }
         }
     } else {
         echo '  Skipping ' . $packageKey . ', the working copy is dirty.' . PHP_EOL;
     }
 }
function outputMigrationHeadline(AbstractMigration $migration)
{
    global $lastMigration;
    if ($migration !== $lastMigration) {
        outputHeadline('Migration %s (%s)', 1, array($migration->getIdentifier(), formatVersion($migration->getVersionNumber())));
        $description = $migration->getDescription();
        if ($description !== null) {
            outputLine($description);
            outputLine();
        }
        $lastMigration = $migration;
    }
}