55 * @link https://matomo.org
66 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
77 */
8+
89namespace Piwik \Plugins \TagManager \API ;
910
1011use Piwik \API \Request ;
1617use Piwik \Plugins \TagManager \Model \Trigger ;
1718use Piwik \Plugins \TagManager \Model \Variable ;
1819use Exception ;
20+ use Piwik \Date ;
21+ use Piwik \Plugins \TagManager \Dao \TagsDao ;
22+ use Piwik \Plugins \TagManager \Dao \TriggersDao ;
23+ use Piwik \Plugins \TagManager \Dao \VariablesDao ;
1924use Piwik \Plugins \TagManager \Template \Tag \TagsProvider ;
2025use Piwik \Plugins \TagManager \Template \Trigger \TriggersProvider ;
2126use Piwik \Plugins \TagManager \Template \Variable \VariablesProvider ;
@@ -62,16 +67,48 @@ class Import
6267 */
6368 private $ accessValidator ;
6469
65- public function __construct (Tag $ tags , Trigger $ triggers , Variable $ variables , Container $ containers , AccessValidator $ accessValidator , TagsProvider $ tagsProvider , TriggersProvider $ triggersProvider , VariablesProvider $ variablesProvider )
66- {
70+ /**
71+ * @var TagsDao
72+ */
73+ protected $ tagsDao ;
74+
75+ /**
76+ * @var TriggersDao
77+ */
78+ protected $ triggersDao ;
79+
80+ /**
81+ * @var VariablesDao
82+ */
83+ protected $ variablesDao ;
84+
85+ public function __construct (
86+ Tag $ tags ,
87+ Trigger $ triggers ,
88+ Variable $ variables ,
89+ Container $ containers ,
90+ AccessValidator $ accessValidator ,
91+ TagsProvider $ tagsProvider ,
92+ TriggersProvider $ triggersProvider ,
93+ VariablesProvider $ variablesProvider ,
94+ TagsDao $ tagsDao ,
95+ TriggersDao $ triggersDao ,
96+ VariablesDao $ variablesDao
97+ ) {
6798 $ this ->tags = $ tags ;
6899 $ this ->triggers = $ triggers ;
69100 $ this ->variables = $ variables ;
70101 $ this ->containers = $ containers ;
102+
71103 $ this ->accessValidator = $ accessValidator ;
104+
72105 $ this ->tagsProvider = $ tagsProvider ;
73106 $ this ->triggersProvider = $ triggersProvider ;
74107 $ this ->variablesProvider = $ variablesProvider ;
108+
109+ $ this ->tagsDao = $ tagsDao ;
110+ $ this ->triggersDao = $ triggersDao ;
111+ $ this ->variablesDao = $ variablesDao ;
75112 }
76113
77114 public function checkImportContainerIsPossible ($ exportedContainerVersion , $ idSite , $ idContainer )
@@ -119,17 +156,10 @@ public function importContainerVersion($exportedContainerVersion, $idSite, $idCo
119156 {
120157 $ this ->checkImportContainerIsPossible ($ exportedContainerVersion , $ idSite , $ idContainer );
121158
122- foreach ($ this ->tags ->getContainerTags ($ idSite , $ idContainerVersion ) as $ tag ) {
123- $ this ->tags ->deleteContainerTag ($ idSite , $ idContainerVersion , $ tag ['idtag ' ]);
124- }
125-
126- foreach ($ this ->triggers ->getContainerTriggers ($ idSite , $ idContainerVersion ) as $ trigger ) {
127- $ this ->triggers ->deleteContainerTrigger ($ idSite , $ idContainerVersion , $ trigger ['idtrigger ' ]);
128- }
129-
130- foreach ($ this ->variables ->getContainerVariables ($ idSite , $ idContainerVersion ) as $ variable ) {
131- $ this ->variables ->deleteContainerVariable ($ idSite , $ idContainerVersion , $ variable ['idvariable ' ]);
132- }
159+ $ now = Date::now ()->getDatetime ();
160+ $ this ->tagsDao ->deleteContainerTags ($ idSite , $ idContainerVersion , $ now );
161+ $ this ->triggersDao ->deleteContainerTriggers ($ idSite , $ idContainerVersion , $ now );
162+ $ this ->variablesDao ->deleteContainerVariables ($ idSite , $ idContainerVersion , $ now );
133163
134164 $ ecv = $ exportedContainerVersion ;
135165
@@ -145,7 +175,7 @@ public function importContainerVersion($exportedContainerVersion, $idSite, $idCo
145175 'defaultValue ' => $ variable ['default_value ' ],
146176 'lookupTable ' => $ variable ['lookup_table ' ],
147177 ));
148- } catch (EntityRecursionException $ e ){
178+ } catch (EntityRecursionException $ e ) {
149179 throw new \Exception (Piwik::translate ('TagManager_EntityRecursionExceptionForVariable ' , array ($ variable ['name ' ] . '( ' . $ variable ['type ' ] . ') ' )));
150180 }
151181 }
@@ -200,6 +230,4 @@ public function importContainerVersion($exportedContainerVersion, $idSite, $idCo
200230 ));
201231 }
202232 }
203-
204-
205233}
0 commit comments