Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
feature(Setup/Initialize): add create tags
Browse files Browse the repository at this point in the history
expects $tags with the following structure:

$tags = [
  [
     'name' => 'Mitglied',
      'description' => 'gehört zu einem Mitglied',
      'color' => '#339966'
  ], [...]
]
  • Loading branch information
pschuele committed Aug 12, 2021
1 parent 7d9d512 commit 6b75fbb
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tine20/Setup/Initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,51 @@ public static function createCustomFields(array $customfields)
}
}
}

/**
* expects $tags with the following structure:
*
* $tags = [
* [
* 'name' => 'Mitglied',
* 'description' => 'gehört zu einem Mitglied',
* 'color' => '#339966'
* ], [...]
* ]
*
* @param array $tags
* @throws Tinebase_Exception_AccessDenied
* @throws Tinebase_Exception_InvalidArgument
* @throws Tinebase_Exception_Record_DefinitionFailure
* @throws Tinebase_Exception_Record_Validation
*/
public static function createSharedTags(array $tags)
{
$controller = Tinebase_Tags::getInstance();

// TODO needed?
// $user = Setup_Update_Abstract::getSetupFromConfigOrCreateOnTheFly();
// Tinebase_Core::set(Tinebase_Core::USER, $user);

foreach ($tags as $tag) {
$sharedTag = new Tinebase_Model_Tag(array(
'type' => Tinebase_Model_Tag::TYPE_SHARED,
'name' => $tag['name'],
'description' => $tag['description'],
'color' => $tag['color'],
));

$savedSharedTag = $controller->createTag($sharedTag);
$controller->setContexts(array('any'), $savedSharedTag->getId());

$right = new Tinebase_Model_TagRight(array(
'tag_id' => $savedSharedTag->getId(),
'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE,
'account_id' => 0,
'view_right' => true,
'use_right' => true,
));
$controller->setRights($right);
}
}
}

0 comments on commit 6b75fbb

Please sign in to comment.