static function create($session_id) { if ($session_id == null || $session_id == '') { echo 'A session_id is required.<br>'; return false; } if (!Workflow_Sessions::session_id_exists($workflow_name)) { $expiration_date = date("YmdHis") + 1000000; //add a day to it using the YmdHis format $session_expiration = sprintf("%.0f", $expiration_date); $insert_record = db_query("INSERT into {apiary_project_workflow_sessions} (session_id, session_expiration)\r\n\t VALUES ('%s', '%s')", $session_id, $session_expiration); return $insert_record; } else { echo "Session ID already exists. <br>"; } return false; }
static function releaseImageLock($image_pid) { global $user; $now = date("YmdHis"); $datastream_name = "status"; $datastream_label = "Image Status"; $session_id = $_SESSION['apiary_session_id']; if ($session_id == '') { $session_id = $_SESSION['apiary_cleared_session_id']; } $dom = FedoraObject::getManagedXMLDom($image_pid, $datastream_name); if ($dom != false) { if ($dom->getElementsByTagName('locked')->item(0)->nodeValue != "false") { if (!empty($dom->getElementsByTagName('locked_session')->item(0)->nodeValue)) { $locked_session = $dom->getElementsByTagName('locked_session')->item(0)->nodeValue; if ($dom->getElementsByTagName('locked_by')->item(0)->nodeValue == $user->name && $locked_session == $session_id) { $dom->getElementsByTagName('locked')->item(0)->nodeValue = "false"; } else { if (false) { //could add an override if the user has some admin right } else { $last_locked_time = $dom->getElementsByTagName('locked_time')->item(0)->nodeValue; $apiary_timeout = variable_get('apiary_object_timeout', '1800'); $last_locked_timeout = $last_locked_time + $apiary_timeout; if ($now > $last_locked_timeout || !Workflow_Sessions::active_session($locked_session)) { $dom->getElementsByTagName('locked')->item(0)->nodeValue = "false"; } else { //cannot unlock this record return false; } } } } } $dom->getElementsByTagName('locked')->item(0)->nodeValue = "false"; } else { //create status datastream! $dom = AP_Image::generateImageStatusDom("false", $user->name, $now, $session_id); } //We don't get here if we fail if (FedoraObject::createManagedXMLDom($image_pid, $datastream_name, $datastream_label, $dom)) { include_once drupal_get_path('module', 'apiary_project') . '/workflow/include/search.php'; $search_instance = new search(); $search_instance->index($image_pid); return FedoraObject::getManagedXMLDom($image_pid, $datastream_name); } }
static function isLockedExpired($locked_time, $locked_session) { $now = date("YmdHis"); $apiary_timeout = variable_get('apiary_object_timeout', '1800'); if ($now > $locked_time + $apiary_timeout) { return true; } else { if (!Workflow_Sessions::active_session($locked_session)) { return true; } else { return false; } } }
function delete_session() { if (Workflow_Sessions::delete($_SESSION['apiary_session_id']) > 0) { $_SESSION['apiary_session_id'] = ''; echo "success"; } else { echo "failed"; } }