コード例 #1
0
ファイル: Object.php プロジェクト: youprofit/casebox
 /**
  * copy an object to $pid or over $targetId
  *
  * better way to copy an object over another one is to delete the target,
  * but this could be very dangerous. We could delete required/important data
  * so i suggest to just mark overwriten object with dstatus = 3.
  * But in this situation appears another problem with child nodes.
  * Childs should be moved to new parent.
  *
  * @param  int $pid      if not specified then will be set to pid of targetId
  * @param  int $targetId
  * @return int the id of copied object
  */
 public function copyTo($pid = false, $targetId = false)
 {
     // check input params
     if (!is_numeric($this->id) || !is_numeric($pid) && !is_numeric($targetId)) {
         return false;
     }
     /* security check */
     if (!\CB\Security::canRead($this->id)) {
         return false;
     }
     /* end of security check */
     if (is_numeric($targetId)) {
         /* target security check */
         if (!\CB\Security::canWrite($targetId)) {
             return false;
         }
         /* end of target security check */
         // marking overwriten object with dstatus = 3
         DM\Tree::update(array('id' => $targetId, 'updated' => 1, 'dstatus' => 3, 'did' => User::getId()));
         $r = DM\Tree::read($targetId);
         if (!empty($r)) {
             $pid = $r['pid'];
         }
     } else {
         /* pid security check */
         if (!\CB\Security::canWrite($pid)) {
             return false;
         }
         /* end of pid security check */
     }
     /* check again if we have pid set
            It can be unset when not existent $targetId is specified
        */
     if (!is_numeric($pid)) {
         return false;
     }
     // copying the object to $pid
     $objectId = DM\Tree::copy($this->id, $pid);
     /* we have now object created, so we start copy all its possible data:
            - tree_info is filled automaticly by trigger
            - custom security rules from tree_acl
            - custom object data
        */
     // copy node custom security rules if set
     \CB\Security::copyNodeAcl($this->id, $objectId);
     $this->copyCustomDataTo($objectId);
     // move childs from overwriten targetId (which has been marked with dstatus = 3)
     // to newly copied object
     if (is_numeric($targetId)) {
         // DM\Tree::update(
         // )
         DM\Tree::moveActiveChildren($targetId, $this->id);
     }
     return $objectId;
 }