From 30747eccfd0b8b4dbb8d6b2cc7a98bdb8de8b12e Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Mon, 12 Dec 2016 00:01:34 -0200 Subject: [PATCH] Add Deafault and config map to load default seal (refs #20) --- conf-base.php | 5 ++++- db-updates.php | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/conf-base.php b/conf-base.php index 801804e..e055a56 100644 --- a/conf-base.php +++ b/conf-base.php @@ -6,5 +6,8 @@ 'app.enabled.apps' => false, 'maps.center' => [-23.633201663141417, -46.6043472290039], 'maps.zoom.default' => 11, - 'export.excelName' => 'gestao-de-hortas-dados-exportados.xls' + 'export.excelName' => 'gestao-de-hortas-dados-exportados.xls', + // assuming that's a first instalation and the default seal will be the seal '2' + // if the verified seal is other needs to change this ID + 'app.verifiedSealsIds' => [2] ]; diff --git a/db-updates.php b/db-updates.php index b158229..15549f0 100644 --- a/db-updates.php +++ b/db-updates.php @@ -3,6 +3,7 @@ use MapasCulturais\Entities\Agent; use MapasCulturais\Entities\Seal; use MapasCulturais\Entities\SpaceSealRelation; +use MapasCulturais\Entities\AgentSealRelation; $app = MapasCulturais\App::i(); $em = $app->em; @@ -186,4 +187,29 @@ $seal_relation->save(); } }, + 'hor: add default seal to all agents' => function() use($app){ + $app->em->flush(); + + $app->user = $app->repo('User')->find(1); + $app->auth->authenticatedUser = $app->repo('User')->find(1); + $owner_agent = $app->user->profile; + $seal = $app->repo('Seal')->findOneBy(['name' => 'SME']); + + if(!$seal){ + echo "Seal \"SME\" needs to be created before this db-update run"; + return false; + } + $agents = $app->repo('Agent')->findAll(); + foreach ($agents as $agent) { + $seal_relation = new AgentSealRelation; + $seal_relation->seal = $seal; + $seal_relation->objectId = $agent->id; + $seal_relation->object_type = $agent->entityClassName; + $seal_relation->agent = $owner_agent; + $seal_relation->owner = $agent; + $seal_relation->owner_relation = $owner_agent; + echo "\nAdding seal \"$seal->name\" to agent \"$agent->name\""; + $seal_relation->save(); + } + } ]; \ No newline at end of file