/** * * @global wpdb $wpdb * @staticvar boolean $init * @return type */ function TryScanLock() { global $wpdb; if (!self::$_scan_lock_init) { self::$_scan_lock_init = true; self::$_file_scan_locks = array(); self::$_cat_scan_locks = array(); register_shutdown_function(array(__CLASS__, '_removeScanLocks')); } if ($this->is_file) { $sla =& self::$_file_scan_locks; } else { $sla =& self::$_cat_scan_locks; } $table = $this->is_file ? $wpdb->wpfilebase_files : $wpdb->wpfilebase_cats; $prefix = $this->is_file ? 'file' : 'cat'; $slf = "{$prefix}_scan_lock"; $now = time(); $lock_time = $now + self::SCAN_LOCK_TIMEOUT; $id = $this->GetId(); // first check if we own the lock and update if necessary if (isset($sla[$id])) { //echo "TryLock $this @".__LINE__." isset"; return $lock_time > $sla[$id] ? $wpdb->update($table, array($slf => $lock_time), array("{$prefix}_id" => $id, $slf => $sla[$id])) && ($sla[$id] = $this->{$slf} = $lock_time) : true; } // actually try to set the lock and store it in $sla if success return $wpdb->query($wpdb->prepare("\n\t\t\tUPDATE `{$table}`\n\t\t\tSET `{$slf}` = %d\n\t\t\tWHERE (`{$prefix}_id` = %d) AND (`{$slf}` < %d)\n\t\t\t", $lock_time, $id, $now)) && ($sla[$id] = $this->{$slf} = $lock_time); }