-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Afform - reset managed entities when deleting a dashlet #22957
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Civi\Api4\Action\Afform; | ||
|
||
use Civi\Api4\Generic\Result; | ||
|
||
/** | ||
* @inheritDoc | ||
* @package Civi\Api4\Action\Afform | ||
*/ | ||
class Revert extends \Civi\Api4\Generic\BasicBatchAction { | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $flushManaged = FALSE; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $flushMenu = FALSE; | ||
|
||
/** | ||
* Revert every record, and flush caches at the end. | ||
* | ||
* @inheritDoc | ||
*/ | ||
protected function processBatch(Result $result, array $items) { | ||
parent::processBatch($result, $items); | ||
|
||
// We may have changed list of files covered by the cache. | ||
_afform_clear(); | ||
|
||
if ($this->flushManaged) { | ||
// FIXME: more targeted reconciliation | ||
\CRM_Core_ManagedEntities::singleton()->reconcile(); | ||
} | ||
if ($this->flushMenu) { | ||
\CRM_Core_Menu::store(); | ||
} | ||
} | ||
|
||
/** | ||
* Revert (delete) a record. | ||
* | ||
* @inheritDoc | ||
*/ | ||
protected function doTask($item) { | ||
/** @var \CRM_Afform_AfformScanner $scanner */ | ||
$scanner = \Civi::service('afform_scanner'); | ||
$files = [ | ||
\CRM_Afform_AfformScanner::METADATA_FILE, | ||
\CRM_Afform_AfformScanner::LAYOUT_FILE, | ||
]; | ||
|
||
foreach ($files as $file) { | ||
$metaPath = $scanner->createSiteLocalPath($item['name'], $file); | ||
if (file_exists($metaPath)) { | ||
if (!@unlink($metaPath)) { | ||
throw new \API_Exception("Failed to remove afform overrides in $file"); | ||
} | ||
} | ||
} | ||
|
||
$original = (array) $scanner->getMeta($item['name']); | ||
|
||
// If the dashlet setting changed, managed entities must be reconciled | ||
if ( | ||
(empty($item['is_dashlet']) !== empty($original['is_dashlet'])) || | ||
($item['is_dashlet'] && ($item['title'] ?? '') !== ($original['title'] ?? '')) | ||
) { | ||
$this->flushManaged = TRUE; | ||
} | ||
|
||
// If the server_route changed, reset menu cache | ||
if (($item['server_route'] ?? '') !== ($original['server_route'] ?? '')) { | ||
$this->flushMenu = TRUE; | ||
} | ||
|
||
return $item; | ||
} | ||
|
||
/** | ||
* Adds extra return params so caches can be conditionally flushed. | ||
* | ||
* @return string[] | ||
*/ | ||
protected function getSelect() { | ||
return ['name', 'title', 'is_dashlet', 'server_route']; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test revealed this variable was leaky. The purpose of this function is to rebuild this array, but it needs to be reset first due to the singleton pattern.