Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix layout styles after run migration #6881

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ HumHub Changelog
- Enh #25: Improve contrast of @default button color
- Fix #6889: Issue with modal boxes when positioning an element at the bottom of the screen
- Enh #6892: Implement new method `getCommentUrl` for comment permanent URL
- Fix #6881: Fix layout styles after run migration
- Enh #6904: Content Search: Add Tests regarding `state`
- Enh #2758: Make sure we understand how to configure who receives notifications about new users to approve
- Fix #6908: Fix default mentioning URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
*/
class InformationController extends Controller
{
public const DB_ACTION_CHECK = 0;
public const DB_ACTION_RUN = 1;
public const DB_ACTION_PENDING = 2;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -87,23 +83,14 @@ public function actionPrerequisites()
return $this->render('prerequisites', ['checks' => SelfTest::getResults()]);
}

public function actionDatabase(int $migrate = self::DB_ACTION_CHECK)
public function actionDatabase(int $migrate = MigrationService::DB_ACTION_CHECK)
{
$migrationService = MigrationService::create();

if ($migrate === self::DB_ACTION_RUN) {
$migrationService->migrateUp();
$migrationOutput = sprintf(
"%s\n%s",
$migrationService->getLastMigrationOutput(),
SettingController::flushCache()
);
} else {
$migrate = $migrationService->hasMigrationsPending()
? self::DB_ACTION_PENDING
: self::DB_ACTION_CHECK;

$migrationOutput = $migrationService->getLastMigrationOutput();
$migrate = $migrationService->runAction($migrate);

if ($migrate === MigrationService::DB_ACTION_SESSION) {
return $this->redirect(['/admin/information/database']);
}

$databaseInfo = new DatabaseInfo(Yii::$app->db->dsn);
Expand All @@ -118,7 +105,7 @@ public function actionDatabase(int $migrate = self::DB_ACTION_CHECK)
[
'rebuildSearchRunning' => QueueHelper::isQueued($rebuildSearchJob),
'databaseName' => $databaseInfo->getDatabaseName(),
'migrationOutput' => $migrationOutput,
'migrationOutput' => $migrationService->getLastMigrationOutput(),
'migrationStatus' => $migrate,
]
);
Expand Down
19 changes: 0 additions & 19 deletions protected/humhub/modules/admin/controllers/SettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public function actionCaching()
{
$form = new CacheSettingsForm();
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
self::flushCache();
$this->view->success(Yii::t('AdminModule.settings', 'Saved and flushed cache'));
return $this->redirect(['/admin/setting/caching']);
}
Expand Down Expand Up @@ -399,22 +398,4 @@ public function actionAdvanced()
]
);
}

/**
* @return string Activity output that can be used for logging
* @since 1.16
*/
public static function flushCache(): string
{
$output = "Flushing cache ...";
Yii::$app->cache->flush();

$output .= "\nFlushing asset manager ...";
Yii::$app->assetManager->clear();

$output .= "\nFlushing theme cache ...";
Yii::$app->view->theme->activate();

return $output;
}
}
18 changes: 18 additions & 0 deletions protected/humhub/modules/admin/models/forms/CacheSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function save()
$settingsManager->set('cache.reloadableScripts', $this->reloadableScripts);

DynamicConfig::rewrite();
self::flushCache();

return true;
}
Expand Down Expand Up @@ -134,4 +135,21 @@ public function getReloadableScriptsAsArray()
return [];
}

/**
* @return string Activity output that can be used for logging
* @since 1.16
*/
public static function flushCache(): string
{
$output = "Flushing cache ...";
Yii::$app->cache->flush();

$output .= "\nFlushing asset manager ...";
Yii::$app->assetManager->clear();

$output .= "\nFlushing theme cache ...";
Yii::$app->view->theme->activate();

return $output;
}
}
6 changes: 3 additions & 3 deletions protected/humhub/modules/admin/views/information/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

use humhub\libs\Html;
use humhub\modules\admin\controllers\InformationController;
use humhub\modules\ui\view\components\View;
use humhub\services\MigrationService;

/**
* @var $this View
Expand All @@ -33,7 +33,7 @@
</div>

<div>
<?php if ($migrationStatus === InformationController::DB_ACTION_PENDING): ?>
<?php if ($migrationStatus === MigrationService::DB_ACTION_PENDING): ?>
<p><?= Yii::t('AdminModule.information', 'Outstanding database migrations:'); ?></p>
<div class="well">
<pre>
Expand All @@ -50,7 +50,7 @@
]
); ?>
</p>
<?php elseif ($migrationStatus === InformationController::DB_ACTION_RUN): ?>
<?php elseif ($migrationStatus === MigrationService::DB_ACTION_RUN): ?>
<p><?= Yii::t('AdminModule.information', 'Database migration results:'); ?></p>
<div class="well">
<pre>
Expand Down
51 changes: 51 additions & 0 deletions protected/humhub/services/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use humhub\events\MigrationEvent;
use humhub\helpers\DataTypeHelper;
use humhub\interfaces\ApplicationInterface;
use humhub\modules\admin\models\forms\CacheSettingsForm;
use Throwable;
use uninstall;
use Yii;
Expand Down Expand Up @@ -43,6 +44,12 @@ class MigrationService extends Component
private ?int $lastMigrationResult = null;
private ?string $lastMigrationOutput = null;

public const DB_ACTION_CHECK = 0;
public const DB_ACTION_RUN = 1;
public const DB_ACTION_PENDING = 2;
public const DB_ACTION_SESSION = 3;
private const SESSION_LAST_MIGRATION_OUTPUT = 'DBLastMigrationOutput';

/**
* @param Module|ApplicationInterface|Application|null $module
*/
Expand Down Expand Up @@ -353,4 +360,48 @@ public static function create(?BaseModule $module = null): self
/** @noinspection PhpUnhandledExceptionInspection */
return Yii::createObject(static::class, [$module]);
}

/**
* Store the last migration output in Session
*/
private function storeLastMigrationOutput(): void
{
Yii::$app->session->set(self::SESSION_LAST_MIGRATION_OUTPUT, $this->getLastMigrationOutput());
}

/**
* Restore the last migration output from Session
*/
private function restoreLastMigrationOutput(): void
{
$this->lastMigrationOutput = Yii::$app->session->get(self::SESSION_LAST_MIGRATION_OUTPUT);
Yii::$app->session->remove(self::SESSION_LAST_MIGRATION_OUTPUT);
}

/**
* Run migration by requested action
*
* @param int $action Requested action
* @return int Output action
*/
public function runAction(int $action = self::DB_ACTION_CHECK): int
{
if ($action === self::DB_ACTION_RUN) {
$this->migrateUp();
$this->lastMigrationOutput .= "\n" . CacheSettingsForm::flushCache();
$this->storeLastMigrationOutput();
return self::DB_ACTION_SESSION;
}

// Try to restore last migration result from store(Sessions)
$this->restoreLastMigrationOutput();

if ($this->lastMigrationOutput === null) {
return $this->hasMigrationsPending()
? self::DB_ACTION_PENDING
: self::DB_ACTION_CHECK;
}

return self::DB_ACTION_RUN;
}
}