Differential D14064 Diff 34068 src/applications/config/controller/PhabricatorConfigPurgeCacheController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/config/controller/PhabricatorConfigPurgeCacheController.php
- This file was added.
| <?php | |||||
| final class PhabricatorConfigPurgeCacheController | |||||
| extends PhabricatorConfigController { | |||||
epriestley: This should likely extend `PhabricatorConfigController` instead.
It can then inherit the… | |||||
| public function handleRequest(AphrontRequest $request) { | |||||
| $viewer = $this->getViewer(); | |||||
| $cancel_uri = $this->getApplicationURI('cache/'); | |||||
| $opcode_cache = PhabricatorOpcodeCacheSpec::getActiveCacheSpec(); | |||||
| $data_cache = PhabricatorDataCacheSpec::getActiveCacheSpec(); | |||||
| $opcode_clearable = $opcode_cache->getClearCacheCallback(); | |||||
| $data_clearable = $data_cache->getClearCacheCallback(); | |||||
| if (!$opcode_clearable && !$data_clearable) { | |||||
Not Done Inline ActionsMinor nit, but maybe define $cancel_uri = $this->getApplicationURI('cache/'); here to slightly reduce repetition, as this URI is hard-coded in three places in the remainder of the controller. epriestley: Minor nit, but maybe define `$cancel_uri = $this->getApplicationURI('cache/');` here to… | |||||
| return $this->newDialog() | |||||
| ->setTitle(pht('No Caches to Reset')) | |||||
| ->appendParagraph( | |||||
| pht('None of the caches on this page can be cleared.')) | |||||
| ->addCancelButton($cancel_uri); | |||||
| } | |||||
| if ($request->isDialogFormPost()) { | |||||
| if ($opcode_clearable) { | |||||
Not Done Inline ActionsIf one of these caches is missing but the other is present (e.g., we have OpCache but not APCu) I think this will try to clear a null callback and produce an error like this:
Likely fix is testing if the callbacks are set before invoking them. epriestley: If one of these caches is missing but the other is present (e.g., we have OpCache but not APCu)… | |||||
| call_user_func($opcode_cache->getClearCacheCallback()); | |||||
| } | |||||
| if ($data_clearable) { | |||||
| call_user_func($data_cache->getClearCacheCallback()); | |||||
| } | |||||
| return id(new AphrontRedirectResponse())->setURI($cancel_uri); | |||||
| } | |||||
| $caches = id(new PHUIPropertyListView()) | |||||
| ->setUser($viewer); | |||||
| if ($opcode_clearable) { | |||||
| $caches->addProperty( | |||||
| pht('Opcode'), | |||||
| $opcode_cache->getName()); | |||||
| } | |||||
| if ($data_clearable) { | |||||
| $caches->addProperty( | |||||
| pht('Data'), | |||||
| $data_cache->getName()); | |||||
| } | |||||
| return $this->newDialog() | |||||
| ->setTitle(pht('Really Clear Cache?')) | |||||
| ->setShortTitle(pht('Really Clear Cache')) | |||||
| ->appendParagraph(pht('This will only affect the current web '. | |||||
| 'frontend. Daemons and any other web frontends may continue '. | |||||
Not Done Inline ActionsConsider naming the button "Clear Cache" for clarity. epriestley: Consider naming the button "Clear Cache" for clarity. | |||||
| 'to use older, cached code from their opcache.')) | |||||
| ->appendParagraph(pht('The following caches will be cleared:')) | |||||
| ->appendChild($caches) | |||||
| ->addSubmitButton(pht('Clear Cache')) | |||||
| ->addCancelButton($cancel_uri); | |||||
| } | |||||
| } | |||||
This should likely extend PhabricatorConfigController instead.
It can then inherit the shouldRequireAdmin() implementation automatically, and doesn't need an explicit implementation.