1717
1818use Pimcore \Extension \Bundle \Installer \AbstractInstaller ;
1919use Pimcore \Logger ;
20+ use Pimcore \Model \Object \Objectbrick \Definition ;
2021
2122class Installer extends AbstractInstaller
2223{
@@ -25,12 +26,14 @@ public function install()
2526 $ this ->installPermissions ();
2627 $ this ->installDatabaseTables ();
2728 $ this ->installClasses ();
29+ $ this ->installBricks ();
2830
2931 return true ;
3032 }
3133
3234 public function isInstalled ()
3335 {
36+
3437 $ result = \Pimcore \Db::get ()->fetchAll ('SHOW TABLES LIKE "plugin_cmf_segment_assignment" ' );
3538
3639 return !empty ($ result );
@@ -230,7 +233,7 @@ public function installDatabaseTables()
230233 }
231234 }
232235
233- public static function installClasses ()
236+ public function installClasses ()
234237 {
235238 $ sourcePath = __DIR__ .'/../install/class_source ' ;
236239
@@ -245,19 +248,49 @@ public static function installClasses()
245248 self ::installClass ('LinkActivityDefinition ' , $ sourcePath .'/class_LinkActivityDefinition_export.json ' );
246249 }
247250
251+ public function installBricks ()
252+ {
253+ $ sourcePath = __DIR__ .'/../install/objectbrick_source ' ;
254+
255+ self ::installBrick ('OAuth1Token ' , $ sourcePath .'/objectbrick_OAuth1Token_export.json ' );
256+ self ::installBrick ('OAuth2Token ' , $ sourcePath .'/objectbrick_OAuth2Token_export.json ' );
257+ }
258+
248259 public static function installClass ($ classname , $ filepath )
249260 {
250261 $ class = \Pimcore \Model \DataObject \ClassDefinition::getByName ($ classname );
251262 if (!$ class ) {
252263 $ class = new \Pimcore \Model \DataObject \ClassDefinition ();
253264 $ class ->setName ($ classname );
254265 $ class ->setGroup ('CustomerManagement ' );
266+
267+ $ json = file_get_contents ($ filepath );
268+
269+ $ success = \Pimcore \Model \DataObject \ClassDefinition \Service::importClassDefinitionFromJson ($ class , $ json );
270+ if (!$ success ) {
271+ Logger::err ("Could not import $ classname Class. " );
272+ }
255273 }
256- $ json = file_get_contents ($ filepath );
274+ }
275+
276+ public static function installBrick ($ brickKey , $ filepath )
277+ {
278+ try {
279+ $ brick = \Pimcore \Model \DataObject \Objectbrick \Definition::getByKey ($ brickKey );
280+ } catch (\Exception $ e ) {
281+ $ brick = null ;
282+ }
283+
284+ if (!$ brick ) {
285+ $ brick = new \Pimcore \Model \DataObject \Objectbrick \Definition ;
286+ $ brick ->setKey ($ brickKey );
287+
288+ $ json = file_get_contents ($ filepath );
257289
258- $ success = \Pimcore \Model \DataObject \ClassDefinition \Service::importClassDefinitionFromJson ($ class , $ json );
259- if (!$ success ) {
260- Logger::err ("Could not import $ classname Class. " );
290+ $ success = \Pimcore \Model \DataObject \ClassDefinition \Service::importObjectBrickFromJson ($ brick , $ json );
291+ if (!$ success ) {
292+ Logger::err ("Could not import $ brickKey brick. " );
293+ }
261294 }
262295 }
263296}
0 commit comments