-
Notifications
You must be signed in to change notification settings - Fork 59
Mass delete templates in container version #522
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
base: 4.x-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| * @link https://matomo.org | ||
| * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| namespace Piwik\Plugins\TagManager\API; | ||
|
|
||
| use Piwik\API\Request; | ||
|
|
@@ -16,6 +17,10 @@ | |
| use Piwik\Plugins\TagManager\Model\Trigger; | ||
| use Piwik\Plugins\TagManager\Model\Variable; | ||
| use Exception; | ||
| use Piwik\Date; | ||
| use Piwik\Plugins\TagManager\Dao\TagsDao; | ||
| use Piwik\Plugins\TagManager\Dao\TriggersDao; | ||
| use Piwik\Plugins\TagManager\Dao\VariablesDao; | ||
| use Piwik\Plugins\TagManager\Template\Tag\TagsProvider; | ||
| use Piwik\Plugins\TagManager\Template\Trigger\TriggersProvider; | ||
| use Piwik\Plugins\TagManager\Template\Variable\VariablesProvider; | ||
|
|
@@ -62,16 +67,48 @@ class Import | |
| */ | ||
| private $accessValidator; | ||
|
|
||
| public function __construct(Tag $tags, Trigger $triggers, Variable $variables, Container $containers, AccessValidator $accessValidator, TagsProvider $tagsProvider, TriggersProvider $triggersProvider, VariablesProvider $variablesProvider) | ||
| { | ||
| /** | ||
| * @var TagsDao | ||
| */ | ||
| protected $tagsDao; | ||
|
|
||
| /** | ||
| * @var TriggersDao | ||
| */ | ||
| protected $triggersDao; | ||
|
|
||
| /** | ||
| * @var VariablesDao | ||
| */ | ||
| protected $variablesDao; | ||
|
|
||
| public function __construct( | ||
| Tag $tags, | ||
| Trigger $triggers, | ||
| Variable $variables, | ||
| Container $containers, | ||
| AccessValidator $accessValidator, | ||
| TagsProvider $tagsProvider, | ||
| TriggersProvider $triggersProvider, | ||
| VariablesProvider $variablesProvider, | ||
| TagsDao $tagsDao, | ||
| TriggersDao $triggersDao, | ||
| VariablesDao $variablesDao | ||
| ) { | ||
| $this->tags = $tags; | ||
| $this->triggers = $triggers; | ||
| $this->variables = $variables; | ||
| $this->containers = $containers; | ||
|
|
||
| $this->accessValidator = $accessValidator; | ||
|
|
||
| $this->tagsProvider = $tagsProvider; | ||
| $this->triggersProvider = $triggersProvider; | ||
| $this->variablesProvider = $variablesProvider; | ||
|
|
||
| $this->tagsDao = $tagsDao; | ||
| $this->triggersDao = $triggersDao; | ||
| $this->variablesDao = $variablesDao; | ||
| } | ||
|
|
||
| public function checkImportContainerIsPossible($exportedContainerVersion, $idSite, $idContainer) | ||
|
|
@@ -119,17 +156,10 @@ public function importContainerVersion($exportedContainerVersion, $idSite, $idCo | |
| { | ||
| $this->checkImportContainerIsPossible($exportedContainerVersion, $idSite, $idContainer); | ||
|
|
||
| foreach ($this->tags->getContainerTags($idSite, $idContainerVersion) as $tag) { | ||
| $this->tags->deleteContainerTag($idSite, $idContainerVersion, $tag['idtag']); | ||
| } | ||
|
|
||
| foreach ($this->triggers->getContainerTriggers($idSite, $idContainerVersion) as $trigger) { | ||
| $this->triggers->deleteContainerTrigger($idSite, $idContainerVersion, $trigger['idtrigger']); | ||
| } | ||
|
|
||
| foreach ($this->variables->getContainerVariables($idSite, $idContainerVersion) as $variable) { | ||
| $this->variables->deleteContainerVariable($idSite, $idContainerVersion, $variable['idvariable']); | ||
| } | ||
| $now = Date::now()->getDatetime(); | ||
| $this->tagsDao->deleteContainerTags($idSite, $idContainerVersion, $now); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ulcuber Can you create a |
||
| $this->triggersDao->deleteContainerTriggers($idSite, $idContainerVersion, $now); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here call |
||
| $this->variablesDao->deleteContainerVariables($idSite, $idContainerVersion, $now); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here Same here call |
||
|
|
||
| $ecv = $exportedContainerVersion; | ||
|
|
||
|
|
@@ -145,7 +175,7 @@ public function importContainerVersion($exportedContainerVersion, $idSite, $idCo | |
| 'defaultValue' => $variable['default_value'], | ||
| 'lookupTable' => $variable['lookup_table'], | ||
| )); | ||
| } catch (EntityRecursionException $e){ | ||
| } catch (EntityRecursionException $e) { | ||
| throw new \Exception(Piwik::translate('TagManager_EntityRecursionExceptionForVariable', array($variable['name'] . '(' . $variable['type'] . ')'))); | ||
| } | ||
| } | ||
|
|
@@ -200,6 +230,4 @@ public function importContainerVersion($exportedContainerVersion, $idSite, $idCo | |
| )); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,21 @@ public function deleteContainerTag($idSite, $idContainerVersion, $idTag, $delete | |
| Db::query($query, $bind); | ||
| } | ||
|
|
||
| /** | ||
| * @param int $idSite | ||
| * @param int $idContainerVersion | ||
| * @param string $deletedDate | ||
| */ | ||
| public function deleteContainerTags($idSite, $idContainerVersion, $deletedDate) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ulcuber You aiming to update Import.php too with this PR right ? Can you add those changes too ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tried to split it into small atomic independent issues. I'll optimize import next week
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ulcuber Its better to include all such changes in 1 PR so that we can test and ensure that new changes do not lead to any regressions, I would suggest to add the Importer changes in same PR too or folk a branch from this and add those changes if you want to keep your changes separately |
||
| { | ||
| $table = $this->tablePrefixed; | ||
|
|
||
| $query = "UPDATE $table SET status = ?, deleted_date = ? WHERE idsite = ? and idcontainerversion = ? and status != ?"; | ||
| $bind = array(self::STATUS_DELETED, $deletedDate, $idSite, $idContainerVersion, self::STATUS_DELETED); | ||
|
|
||
| Db::query($query, $bind); | ||
| } | ||
|
|
||
| private function enrichTags($tags) | ||
| { | ||
| if (empty($tags)) { | ||
|
|
@@ -217,7 +232,7 @@ private function enrichTag($tag) | |
| $tag['idcontainerversion'] = (int) $tag['idcontainerversion']; | ||
| $tag['fire_delay'] = (int)$tag['fire_delay']; | ||
| $tag['priority'] = (int)$tag['priority']; | ||
|
|
||
| if ($tag['start_date'] === '0000-00-00 00:00:00') { | ||
| $tag['start_date'] = null; | ||
| } | ||
|
|
||
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.
@tsteur any specific reason we deleted 1 tag within a container at a time instead of deleting all at once like in this PR ?