/** * Delete cached entities from all the cache bins associated to restful * resources. * * @param string $cid * The wildcard cache id to invalidate. */ public static function invalidateEntityCache($cid) { $plugins = restful_get_restful_plugins(); foreach ($plugins as $plugin) { $handler = restful_get_restful_handler($plugin['resource'], $plugin['major_version'], $plugin['minor_version']); if (method_exists($handler, 'cacheInvalidate')) { $version = $handler->getVersion(); // Get the uid for the invalidation. try { $uid = $handler->getAccount(FALSE)->uid; } catch (\RestfulUnauthorizedException $e) { // If no user could be found using the handler default to the logged in // user. $uid = $GLOBALS['user']->uid; } $version_cid = 'v' . $version['major'] . '.' . $version['minor'] . '::' . $handler->getResourceName() . '::uu' . $uid; $handler->cacheInvalidate($version_cid . '::' . $cid); } } }
/** * Return the last version for a given resource. * * @param string $resource_name * The name of the resource. * @param int $major_version * Get the last version for this major version. If NULL the last major * version for the resource will be used. * * @return array * Array containing the major_version and minor_version. */ public static function getResourceLastVersion($resource_name, $major_version = NULL) { $resources = array(); // Get all the resources corresponding to the resource name. foreach (restful_get_restful_plugins() as $resource) { if ($resource['resource'] != $resource_name || (isset($major_version) && $resource['major_version'] != $major_version)) { continue; } $resources[$resource['major_version']][$resource['minor_version']] = $resource; } // Sort based on the major version. ksort($resources, SORT_NUMERIC); // Get a list of resources for the latest major version. $resources = end($resources); if (empty($resources)) { return; } // Sort based on the minor version. ksort($resources, SORT_NUMERIC); // Get the latest resource for the minor version. $resource = end($resources); return array($resource['major_version'], $resource['minor_version']); }