Exemplo n.º 1
0
 public static function release_lock($UID, $entity_type, $user)
 {
     // add record to lock table in order to specify that the kbit is no longer locked
     // NOTE: it is recomended to implement the lock in separated class
     if (Lock::is_locked($UID, $entity_type) == false) {
         debugLog::log("<i>[Lock::release_lock]:</i> cannot release lock of [" . $entity_type . "]: " . $UID . " because it is not locked");
         return false;
     }
     if (Lock::is_locked_by_user($UID, $entity_type, $user) == false) {
         debugLog::log("<i>[Lock::release_lock]:</i>cannot release lock of [" . $entity_type . "]: " . $UID . " because it is not locked by the same user");
         return false;
     }
     $dbObj = new dbAPI();
     // disable lock records
     $query = "UPDATE CONTENT_LOCK SET ENABLED = 0 WHERE LOCKED_UID = '" . $UID . "' AND ENTITY_TYPE = '" . $entity_type . "' AND LOCK_STATUS = 'LOCKED' AND ENABLED = 1 ";
     $results = $dbObj->run_query($dbObj->db_get_contentDB(), $query);
     if ($results == false) {
         debugLog::log("<i>[Lock::release_lock]:</i>cannot release lock of [" . $entity_type . "]: " . $UID . " because of database update error");
         return false;
     }
     // add release record
     $query = "INSERT INTO CONTENT_LOCK (LOCKED_UID, ENTITY_TYPE, ENABLED, LOCK_STATUS, USER_ID, CREATION_DATE) VALUES (" . $UID . ", '" . $entity_type . "', 1, 'UNLOCKED', " . $user . ",'" . date("Y-m-d H:i:s") . "')";
     return $dbObj->run_query($dbObj->db_get_contentDB(), $query) == true;
 }