Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tadhgboyle committed Oct 22, 2024
1 parent 4ce68e0 commit c66afb2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
28 changes: 28 additions & 0 deletions core/classes/Core/ComposerModuleWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@ public function getDebugInfo(): array
return $provider->provide();
}

private function migrationsPath(): string
{
return ROOT_PATH . '/vendor/' . $this->_packageName . '/migrations';
}

private function hasMigrations(): bool
{
return file_exists($this->migrationsPath());
}

public function runMigrations(): void
{
if (!$this->hasMigrations()) {
return;
}

PhinxAdapter::migrate($this->getPrivateName(), $this->migrationsPath());
}

public function rollbackMigrations(): void
{
if (!$this->hasMigrations()) {
return;
}

PhinxAdapter::rollback($this->getPrivateName(), $this->migrationsPath());
}

private function callLifecycleHooks(array $hooks): void
{
foreach ($hooks as $callback) {
Expand Down
11 changes: 1 addition & 10 deletions core/classes/Database/PhinxAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ class PhinxAdapter
*
* @param string $module Module name
* @param ?string $migrationDir Migration directory
* @param bool $returnResults If true the results will be returned - otherwise script execution is ended
*
* @return array|void
*/
public static function ensureUpToDate(
string $module,
?string $migrationDir = null,
bool $returnResults = false
?string $migrationDir = null
) {
$module = strtolower($module);

Expand Down Expand Up @@ -52,13 +50,6 @@ static function ($file_name) {
$missing = array_diff($migration_files, $migration_database_entries);
$extra = array_diff($migration_database_entries, $migration_files);

if ($returnResults) {
return [
'missing' => count($missing),
'extra' => count($extra),
];
}

// Likely a pull from the repo dev branch or migrations
// weren't run during an upgrade script.
if (($missing_count = count($missing)) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion core/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
}

// Ensure database is up-to-date
// PhinxAdapter::ensureUpToDate('Core');
PhinxAdapter::ensureUpToDate('Core');

// Error reporting
if (!defined('DEBUGGING')) {
Expand Down
4 changes: 2 additions & 2 deletions modules/Core/pages/panel/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@

// We need to boot it so that the Lifecycle Extenders are loaded
ComposerModuleDiscovery::bootModule($container, $composerModule);
// TODO run their migrations
$composerModule->runMigrations();
$composerModule->onEnable();

DB::getInstance()->update('modules', $_GET['m'], [
Expand Down Expand Up @@ -307,8 +307,8 @@
// Check if composer module
foreach (ComposerModuleDiscovery::discoverModules() as $composerModule) {
if ($composerModule->getName() === $name) { // compare by ID?
$composerModule->rollbackMigrations();
$composerModule->onDisable();
// TODO run their down migrations
}
}
}
Expand Down

0 comments on commit c66afb2

Please sign in to comment.