/** * create or update a server entry * * This function is called when a remote server pings us, to mean its content has changed. * * If the provided URL does not exist, a new server profile is created. * Else the profile is updated only if ping is still allowed for this server profile. * * @see services/ping.php * * @param string the title of the updated server * @param string the link to it * @return string either a null string, or some text describing an error to be inserted into the html response */ public static function ping($title, $url) { global $context; // the entry already exists if ($item = Servers::get_by_url($url)) { // ensure this operation is allowed if (isset($item['process_ping']) && $item['process_ping'] != 'Y') { return 'You are not allowed to perform this operation.'; } // clear the cache for this server Cache::clear('server:' . $item['id']); // update the existing record $query = "UPDATE " . SQL::table_name('servers') . " SET " . "title='" . SQL::escape($title) . "', " . "edit_name='ping', " . "edit_id=0, " . "edit_address='', " . "edit_date='" . gmstrftime('%Y-%m-%d %H:%M:%S') . "'" . " WHERE id = " . SQL::escape($item['id']); if (SQL::query($query) === FALSE) { return 'ERROR'; } // the entry does not exist yet } else { // create a new record $query = "INSERT INTO " . SQL::table_name('servers') . " SET " . "title='" . SQL::escape($title) . "', " . "main_url='" . SQL::escape($url) . "', " . "edit_name='" . SQL::escape($title) . "', " . "edit_id=0, " . "edit_address='', " . "edit_date='" . gmstrftime('%Y-%m-%d %H:%M:%S') . "'"; if (SQL::query($query) === FALSE) { return 'ERROR'; } } // clear the cache for server profiles Cache::clear('servers'); // end of job return NULL; }