Esempio n. 1
0
 /**
  * Synchronizes the account level tag value
  *
  * It does not verify itself whether the cost analytics service is enabled
  *
  * @param   int     $accountId    The identifier of the client's account
  * @param   int     $tagId        The identifier of the clould analytics tag
  * @param   string  $valueId      The identifier of the tag's value
  * @param   string  $valueName    The name of the tag's value
  */
 public function syncValue($accountId, $tagId, $valueId, $valueName)
 {
     if ($accountId === null) {
         $accountId = 0;
     }
     $tag = AccountTagEntity::findPk($accountId, $tagId, $valueId);
     if (!$tag instanceof AccountTagEntity) {
         $tag = new AccountTagEntity();
         $tag->accountId = $accountId;
         $tag->tagId = $tagId;
         $tag->valueId = $valueId;
         $tag->valueName = $valueName;
     } else {
         if ($tag->valueName != $valueName) {
             $tag->valueName = $valueName;
             if ($tagId == TagEntity::TAG_ID_FARM) {
                 foreach ($this->db->GetAll("\n                    SELECT fr.id AS farm_role_id, fr.alias\n                    FROM farm_roles fr\n                    WHERE fr.farmid = ?\n                ", [$valueId]) as $v) {
                     //Updates all related farm roles
                     $this->syncValue($accountId, TagEntity::TAG_ID_FARM_ROLE, $v['farm_role_id'], sprintf('%s', $v['alias']));
                 }
             }
         } else {
             $ignoreupdate = true;
         }
     }
     if (!isset($ignoreupdate)) {
         $tag->save();
     }
 }