Skip to content

Commit

Permalink
de-duplicate flushCache code
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-rueegg committed Dec 14, 2023
1 parent 94a76c7 commit 7760213
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
use Yii;

/**
* Informations
* Information
*
* @since 0.5
*/
class InformationController extends Controller
{
protected const DB_ACTION_CHECK = 'check';
protected const DB_ACTION_RUN = 'run';

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

public function actionDatabase($migrations = 'check')
public function actionDatabase($migrations = self::DB_ACTION_CHECK)
{

$request = Yii::$app->request;

if ($migrations === 'run') {
$migrationOutput = MigrateController::webMigrateAll();

$migrationOutput .= "\nFlushing cache ...";
Yii::$app->cache->flush();

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

$migrationOutput .= "\nFlushing theme cache ...";
Yii::$app->view->theme->variables->flushCache();
if ($migrations === self::DB_ACTION_RUN) {
$migrationOutput = sprintf(
"%s\n%s",
MigrateController::webMigrateAll(),
SettingController::flushCache()
);

$linkRunMigrations = [
'caption' => Yii::t('AdminModule.information', 'Update migration information'),
'action' => 'check',
'action' => self::DB_ACTION_CHECK,
];
} else {
$migrationOutput = MigrateController::webMigrateAll(MigrateController::MIGRATION_ACTION_NEW);
Expand All @@ -112,7 +110,7 @@ public function actionDatabase($migrations = 'check')
} else {
$linkRunMigrations = [
'caption' => Yii::t('AdminModule.information', 'Run migrations'),
'action' => 'run',
'action' => self::DB_ACTION_RUN,
];
}
}
Expand Down
38 changes: 26 additions & 12 deletions protected/humhub/modules/admin/controllers/SettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
*/
class SettingController extends Controller
{

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -125,11 +124,9 @@ public function actionDeleteIconImage()
*/
public function actionCaching()
{
$form = new CacheSettingsForm;
$form = new CacheSettingsForm();
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
Yii::$app->cache->flush();
Yii::$app->assetManager->clear();
Yii::$app->view->theme->activate();
self::flushCache();
$this->view->success(Yii::t('AdminModule.settings', 'Saved and flushed cache'));
return $this->redirect(['/admin/setting/caching']);
}
Expand All @@ -145,7 +142,7 @@ public function actionCaching()
*/
public function actionStatistic()
{
$form = new StatisticSettingsForm;
$form = new StatisticSettingsForm();
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
$this->view->saved();
return $this->redirect([
Expand Down Expand Up @@ -178,7 +175,7 @@ public function actionNotification()
*/
public function actionMailingServer()
{
$form = new MailingSettingsForm;
$form = new MailingSettingsForm();
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
return $this->redirect(['/admin/setting/mailing-server-test']);
}
Expand Down Expand Up @@ -220,7 +217,7 @@ public function actionMailingServerTest()

public function actionDesign()
{
$form = new DesignSettingsForm;
$form = new DesignSettingsForm();
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
$this->view->saved();
return $this->redirect([
Expand All @@ -238,7 +235,7 @@ public function actionDesign()
*/
public function actionFile()
{
$form = new FileSettingsForm;
$form = new FileSettingsForm();
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
$this->view->saved();
return $this->redirect([
Expand Down Expand Up @@ -272,7 +269,7 @@ public function actionFile()
*/
public function actionProxy()
{
$form = new ProxySettingsForm;
$form = new ProxySettingsForm();


if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
Expand Down Expand Up @@ -318,7 +315,7 @@ public function actionLogs()
$dating = "the begining of time";
}

$form = new LogsSettingsForm;
$form = new LogsSettingsForm();
$limitAgeOptions = $form->options;
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {

Expand All @@ -343,7 +340,7 @@ public function actionLogs()
*/
public function actionOembedEdit()
{
$form = new OEmbedProviderForm;
$form = new OEmbedProviderForm();

$name = Yii::$app->request->get('name');
$providers = UrlOembed::getProviders();
Expand Down Expand Up @@ -399,4 +396,21 @@ public function actionAdvanced()
]);
}

/**
* @since 1.16
* @return string Activity output that can be used for logging
*/
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;
}
}

0 comments on commit 7760213

Please sign in to comment.