Skip to content
Snippets Groups Projects
Commit 8d4d0b1b authored by Rich Lott / Artful Robot's avatar Rich Lott / Artful Robot
Browse files

Delete old inlay bundles that have no instance configured

parent 2ef69298
Branches master
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ class CreateBundle extends \Civi\Api4\Generic\AbstractQueryAction {
* @inheritDoc
*/
public function _run(Result $result) {
$recs = $this->getBatchRecords();
$inlayConfig = InlayConfig::singleton();
$settings = $inlayConfig->getSettings();
......@@ -39,6 +40,7 @@ class CreateBundle extends \Civi\Api4\Generic\AbstractQueryAction {
$common = ['inlayEndpoint' => $inlayConfig->getApiEndPoint()];
foreach ($recs as $rec) {
if (empty($rec['error'])) {
......@@ -108,6 +110,26 @@ class CreateBundle extends \Civi\Api4\Generic\AbstractQueryAction {
$url = $inlay->getBundleUrl();
$result[] = ['id' => $inlay->getID(), 'public_id' => $inlay->getPublicID(), 'type' => $inlay->getTypeName(), 'name' => $inlay->getName(), 'javascript' => $url];
}
if (empty($this->where) && empty($this->limit) && empty($this->offset)) {
// We know of every inlay.
$valid = $result->column('public_id');
$filenameStub = Civi::paths()->getPath("[civicrm.files]/inlay-");
$foundFiles = glob($filenameStub . '*.js');
foreach ($foundFiles as $file) {
$foundPublidID = substr(substr($file, strlen($filenameStub)), 0, -3);
if (!in_array($foundPublidID, $valid)) {
$mtime = date('H:i j M Y', filemtime($file));
if (preg_match('/^[0-9a-FA-F]{12}$/', $foundPublidID)) {
unlink($file);
\Civi::log()->warning("Deleted old inlay bundle for $foundPublidID\nat $file updated $mtime as it has no definition.");
}
else {
\Civi::log()->warning("Found unrecognised inlay file at $file (updated $mtime). Consider deleting this.");
}
}
}
}
}
/**
......
......@@ -10,6 +10,10 @@
saving to update the bundle. This can be useful in an upgrader step.
- Adds Inlay.get API parameter to get the config array without validating
(useful for upgrader scripts).
- Fixed a bug that meant certain API updates might give inlays a new public
ID (meaning anyone using the original code would always get the out of date one!)
- Inlay .js bundles without config are now deleted when found, after
bundle updates by cron.
## 1.3.5
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment