Skip to content

Commit

Permalink
Fixed #11829
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 26, 2022
1 parent 22165ac commit 2ed73d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Fixed
- Fixed a bug where the “Edit files uploaded by other users” volume permission was useless unless the “Upload files” permission had been granted. ([#11818](https://github.com/craftcms/cms/issues/11818))
- Fixed a bug where the “Save and add another” entry action was being shown for users without the “Create entries” section permission. ([#11819](https://github.com/craftcms/cms/issues/11819))
- Fixed a PHP error that occurred when garbage collection was run on web requests. ([#11829](https://github.com/craftcms/cms/issues/11829))

## 3.7.52 - 2022-08-23

Expand Down
50 changes: 29 additions & 21 deletions src/services/Gc.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Craft;
use craft\base\ElementInterface;
use craft\config\GeneralConfig;
use craft\console\Application as ConsoleApplication;
use craft\db\Query;
use craft\db\Table;
use craft\elements\Asset;
Expand Down Expand Up @@ -130,7 +131,7 @@ public function hardDeleteVolumes()
return;
}

Console::stdout(" > deleting trashed volumes and their folders ... ");
$this->_stdout(" > deleting trashed volumes and their folders ... ");
$condition = $this->getHardDeleteConditions($generalConfig);

$volumes = (new Query())->select(['id'])->from([Table::VOLUMES])->where($condition)->all();
Expand All @@ -150,7 +151,7 @@ public function hardDeleteVolumes()
}

Volume::deleteAll(['id' => $volumeIds]);
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
Expand All @@ -172,9 +173,9 @@ public function hardDelete($tables)
}

foreach ($tables as $table) {
Console::stdout(" > deleting trashed rows in the `$table` table ... ");
$this->_stdout(" > deleting trashed rows in the `$table` table ... ");
Db::delete($table, $condition);
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}
}

Expand Down Expand Up @@ -214,7 +215,7 @@ public function deletePartialElements(string $elementType, string $table, string
}

$db->createCommand($sql, ['type' => $elementType])->execute();
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

private function _purgeUnsavedDrafts(GeneralConfig $generalConfig)
Expand All @@ -223,9 +224,9 @@ private function _purgeUnsavedDrafts(GeneralConfig $generalConfig)
return;
}

Console::stdout(' > purging unsaved drafts that have gone stale ... ');
$this->_stdout(' > purging unsaved drafts that have gone stale ... ');
Craft::$app->getDrafts()->purgeUnsavedDrafts();
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

private function _purgePendingUsers(GeneralConfig $generalConfig)
Expand All @@ -234,9 +235,9 @@ private function _purgePendingUsers(GeneralConfig $generalConfig)
return;
}

Console::stdout(' > purging pending users with stale activation codes ... ');
$this->_stdout(' > purging pending users with stale activation codes ... ');
Craft::$app->getUsers()->purgeExpiredPendingUsers();
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
Expand All @@ -246,7 +247,7 @@ private function _purgePendingUsers(GeneralConfig $generalConfig)
*/
public function removeEmptyTempFolders(): void
{
Console::stdout(' > removing empty temp folders ... ');
$this->_stdout(' > removing empty temp folders ... ');

$emptyFolders = (new Query())
->from(['folders' => Table::VOLUMEFOLDERS])
Expand All @@ -268,7 +269,7 @@ public function removeEmptyTempFolders(): void
}

VolumeFolder::deleteAll(['id' => array_keys($emptyFolders)]);
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
Expand All @@ -280,22 +281,22 @@ private function _deleteStaleSessions(GeneralConfig $generalConfig)
return;
}

Console::stdout(' > deleting stale user sessions ... ');
$this->_stdout(' > deleting stale user sessions ... ');
$interval = DateTimeHelper::secondsToInterval($generalConfig->purgeStaleUserSessionDuration);
$expire = DateTimeHelper::currentUTCDateTime();
$pastTime = $expire->sub($interval);
Db::delete(Table::SESSIONS, ['<', 'dateUpdated', Db::prepareDateForDb($pastTime)]);
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
* Deletes any feature announcement rows that have gone stale.
*/
private function _deleteStaleAnnouncements(): void
{
Console::stdout(' > deleting stale feature announcements ... ');
$this->_stdout(' > deleting stale feature announcements ... ');
Db::delete(Table::ANNOUNCEMENTS, ['<', 'dateRead', Db::prepareDateForDb(new DateTime('7 days ago'))]);
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}


Expand All @@ -304,7 +305,7 @@ private function _deleteStaleAnnouncements(): void
*/
private function _deleteOrphanedDraftsAndRevisions(): void
{
Console::stdout(' > deleting orphaned drafts and revisions ... ');
$this->_stdout(' > deleting orphaned drafts and revisions ... ');
$db = Craft::$app->getDb();
$elementsTable = Table::ELEMENTS;

Expand All @@ -329,14 +330,14 @@ private function _deleteOrphanedDraftsAndRevisions(): void
$db->createCommand($sql)->execute();
}

Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

private function _deleteOrphanedSearchIndexes(): void
{
Console::stdout(' > deleting orphaned search indexes ... ');
$this->_stdout(' > deleting orphaned search indexes ... ');
Craft::$app->getSearch()->deleteOrphanedIndexes();
Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

private function _gcCache(): void
Expand Down Expand Up @@ -364,15 +365,15 @@ private function _gcCache(): void
return;
}

Console::stdout(' > garbage-collecting data caches ... ');
$this->_stdout(' > garbage-collecting data caches ... ');

if ($hasForceArg) {
$cache->gc(true);
} else {
$cache->gc();
}

Console::stdout("done\n", Console::FG_GREEN);
$this->_stdout("done\n", Console::FG_GREEN);
}

/**
Expand All @@ -395,4 +396,11 @@ protected function getHardDeleteConditions(GeneralConfig $generalConfig): array
}
return $condition;
}

private function _stdout(string $string, ...$format): void
{
if (Craft::$app instanceof ConsoleApplication) {
Console::stdout($string, ...$format);
}
}
}

0 comments on commit 2ed73d8

Please sign in to comment.