def invoke_all(hook): """ Call all init or exit hooks without including all plugins. @param hook The name of the bootstrap hook we wish to invoke. """ for plugin_ in lib_plugin.list_(True, True): lib_plugin.invoke(plugin_, hook)
def watchdog(type, message, variables = [], severity = WATCHDOG_NOTICE, \ link = None): """ Log a system message. @param type The category to which this message belongs. @param message The message to store in the log. See t() for documentation on how message and variables interact. Keep message translatable by not concatenating dynamic values into it! @param variables Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate. @param severity The severity of the message, as per RFC 3164 @param link A link to associate with the message. @see watchdog_severity_levels() """ php.static(watchdog, 'in_error_state', False) # It is possible that the error handling will itself trigger an error. # In that case, we could # end up in an infinite loop. To avoid that, we implement a simple # static semaphore. if (not watchdog.in_error_state): watchdog.in_error_state = True # Prepare the fields to be logged log_message = { 'type': type, 'message': message, 'variables': variables, 'severity': severity, 'link': link, 'user': lib_appglobals.user, 'request_uri': lib_appglobals.base_root + request_uri(), 'referer': php.SERVER['HTTP_REFERER'], 'ip': ip_address(), 'timestamp': REQUEST_TIME } # Call the logging hooks to log/process the message for plugin_ in lib_plugin.implements('watchdog', True): lib_plugin.invoke(plugin_, 'watchdog', log_message) watchdog.in_error_state = False
def watchdog(type, message, variables=[], severity=WATCHDOG_NOTICE, link=None): """ Log a system message. @param type The category to which this message belongs. @param message The message to store in the log. See t() for documentation on how message and variables interact. Keep message translatable by not concatenating dynamic values into it! @param variables Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate. @param severity The severity of the message, as per RFC 3164 @param link A link to associate with the message. @see watchdog_severity_levels() """ php.static(watchdog, "in_error_state", False) # It is possible that the error handling will itself trigger an error. # In that case, we could # end up in an infinite loop. To avoid that, we implement a simple # static semaphore. if not watchdog.in_error_state: watchdog.in_error_state = True # Prepare the fields to be logged log_message = { "type": type, "message": message, "variables": variables, "severity": severity, "link": link, "user": lib_appglobals.user, "request_uri": lib_appglobals.base_root + request_uri(), "referer": php.SERVER["HTTP_REFERER"], "ip": ip_address(), "timestamp": REQUEST_TIME, } # Call the logging hooks to log/process the message for plugin_ in lib_plugin.implements("watchdog", True): lib_plugin.invoke(plugin_, "watchdog", log_message) watchdog.in_error_state = False
def drupal_get_schema(table=None, rebuild=False): """ Get the schema definition of a table, or the whole database schema. The returned schema will include any modifications made by any module that implements hook_schema_alter(). @param $table The name of the table. If not given, the schema of all tables is returned. @param $rebuild If true, the schema will be rebuilt instead of retrieved from the cache. """ php.static(drupal_get_schema, 'schema', []) if (php.empty(drupal_get_schema.schema) or rebuild): # Try to load the schema from cache. cached = lib_cache.get('schema') if (not rebuild and cached): drupal_get_schema.schema = cached.data # Otherwise, rebuild the schema cache. else: drupal_get_schema.schema = [] # Load the .install files to get hook_schema. # On some databases this function may be called before bootstrap has # been completed, so we force the functions we need to load just in case. if (drupal_function_exists('module_load_all_includes')): # There is currently a bug in module_list() where it caches what it # was last called with, which is not always what you want. # module_load_all_includes() calls module_list(), but if this function # is called very early in the bootstrap process then it will be # uninitialized and therefore return no modules. Instead, we have to # "prime" module_list() here to to values we want, specifically # "yes rebuild the list and don't limit to bootstrap". # TODO: Remove this call after http://drupal.org/node/222109 is fixed. lib_plugin.list(True, False) lib_plugin.load_all_includes('install') # Invoke hook_schema for all modules. for module in module_implements('schema'): current = lib_plugin.invoke(module, 'schema') if (drupal_function_exists('_drupal_initialize_schema')): _drupal_initialize_schema(module, current) schema = php.array_merge(schema, current) if (drupal_function_exists('drupal_alter')): drupal_alter('schema', schema) if (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL): cache_set('schema', schema) if (table is None): return schema elif (php.isset(schema, table)): return schema[table] else: return False
def drupal_get_schema(table=None, rebuild=False): """ Get the schema definition of a table, or the whole database schema. The returned schema will include any modifications made by any module that implements hook_schema_alter(). @param $table The name of the table. If not given, the schema of all tables is returned. @param $rebuild If true, the schema will be rebuilt instead of retrieved from the cache. """ php.static(drupal_get_schema, "schema", []) if php.empty(drupal_get_schema.schema) or rebuild: # Try to load the schema from cache. cached = lib_cache.get("schema") if not rebuild and cached: drupal_get_schema.schema = cached.data # Otherwise, rebuild the schema cache. else: drupal_get_schema.schema = [] # Load the .install files to get hook_schema. # On some databases this function may be called before bootstrap has # been completed, so we force the functions we need to load just in case. if drupal_function_exists("module_load_all_includes"): # There is currently a bug in module_list() where it caches what it # was last called with, which is not always what you want. # module_load_all_includes() calls module_list(), but if this function # is called very early in the bootstrap process then it will be # uninitialized and therefore return no modules. Instead, we have to # "prime" module_list() here to to values we want, specifically # "yes rebuild the list and don't limit to bootstrap". # TODO: Remove this call after http://drupal.org/node/222109 is fixed. lib_plugin.list(True, False) lib_plugin.load_all_includes("install") # Invoke hook_schema for all modules. for module in module_implements("schema"): current = lib_plugin.invoke(module, "schema") if drupal_function_exists("_drupal_initialize_schema"): _drupal_initialize_schema(module, current) schema = php.array_merge(schema, current) if drupal_function_exists("drupal_alter"): drupal_alter("schema", schema) if drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL: cache_set("schema", schema) if table is None: return schema elif php.isset(schema, table): return schema[table] else: return False