Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/Mouf/Database/Patcher/DatabasePatchInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace Mouf\Database\Patcher;

use Doctrine\DBAL\Connection;
use Mouf\Actions\InstallUtils;
use Mouf\ClassProxy;
use Mouf\Installer\PackageInstallerInterface;
use Mouf\InstanceProxy;
Expand Down Expand Up @@ -50,7 +51,7 @@ class DatabasePatchInstaller
* @param string $upSqlFileName The SQL file containing the patch, relative to ROOT_PATH. Should not start with /.
* @param string $downSqlFileName (optional) The SQL file containing the revert patch, relative to ROOT_PATH. Should not start with /.
*/
public static function registerPatch(MoufManager $moufManager, $uniqueName, $description, $upSqlFileName, $downSqlFileName = null)
public static function registerPatch(MoufManager $moufManager, string $uniqueName, string $description, string $upSqlFileName, string $downSqlFileName = null): void
{
// First, let's find if this patch already exists... We assume that $uniqueName = "dbpatch.$instanceName".

Expand Down Expand Up @@ -83,6 +84,35 @@ public static function registerPatch(MoufManager $moufManager, $uniqueName, $des
}
}

/**
* Registers a database migration patch in the patch system.
* Note: the patch will not be executed, only registered in "Awaiting" state.
* The user will have to manually execute the patch.
*
* Note: if the patch already exists, we will update this instance.
*
*/
public static function registerMigrationPatch(MoufManager $moufManager, string $className): void
{
// If the patch already exists, we go in edit mode.
$exists = $moufManager->has($className);

$patchDescriptor = InstallUtils::getOrCreateInstance($className, $className, $moufManager);

$patchDescriptor->getProperty('patchConnection')->setValue($moufManager->getInstanceDescriptor('patchConnection'));

// Register the patch in the patchService.
if (!$exists) {
$patchManager = $moufManager->getInstanceDescriptor('patchService');
$patchs = $patchManager->getProperty('patchs')->getValue();
if ($patchs === null) {
$patchs = array();
}
$patchs[] = $patchDescriptor;
$patchManager->getProperty('patchs')->setValue($patchs);
}
}


public static function generatePatch(MoufManager $moufManager, $description, $instanceName, $selfedit = 'false')
{
Expand Down