Ejemplo n.º 1
0
def variable_init(conf_={}):
    """
   Load the persistent variable table.
  
   The variable table is composed of values that have been saved in the table
   with variable_set() as well as those explicitly specified
   in the configuration file.
  """
    # NOTE: caching the variables improves performance by 20% when serving
    # cached pages.
    cached = lib_cache.get('variables', 'cache')
    if (cached):
        variables = cached.data
    else:
        variables = {}
        result = lib_database.query('SELECT * FROM {variable}')
        while True:
            variable = lib_database.fetch_object(result)
            if (not variable):
                break
            variables[variable.name] = php.unserialize(variable.value)
        lib_cache.set('variables', variables)
    for name, value in conf_.items():
        variables[name] = value
    return variables
Ejemplo n.º 2
0
def variable_init(conf_={}):
    """
   Load the persistent variable table.
  
   The variable table is composed of values that have been saved in the table
   with variable_set() as well as those explicitly specified
   in the configuration file.
  """
    # NOTE: caching the variables improves performance by 20% when serving
    # cached pages.
    cached = lib_cache.get("variables", "cache")
    if cached:
        variables = cached.data
    else:
        variables = {}
        result = lib_database.query("SELECT * FROM {variable}")
        while True:
            variable = lib_database.fetch_object(result)
            if not variable:
                break
            variables[variable.name] = php.unserialize(variable.value)
        lib_cache.set("variables", variables)
    for name, value in conf_.items():
        variables[name] = value
    return variables
Ejemplo n.º 3
0
def table_exists(table):
  """
   Check if a table exists.
  """
  return bool(lib_database.fetch_object(\
    lib_database.query("SHOW TABLES LIKE '{" +  \
    lib_database.escape_table(table)  + "}'")))
Ejemplo n.º 4
0
def table_exists(table):
    """
   Check if a table exists.
  """
    return bool(lib_database.fetch_object(\
      lib_database.query("SHOW TABLES LIKE '{" +  \
      lib_database.escape_table(table)  + "}'")))
Ejemplo n.º 5
0
def list_(refresh = False, bootstrap = True, sort = False, \
    fixed_list = None):
    """
   Collect a list of all loaded plugins. During the bootstrap, return only
   vital plugins. See bootstrap.inc
  
   @param refresh
     Whether to force the plugin list to be regenerated (such as after the
     administrator has changed the system settings).
   @param bootstrap
     Whether to return the reduced set of plugins loaded in "bootstrap mode"
     for cached pages. See bootstrap.inc.
   @param sort
     By default, plugins are ordered by weight and filename,
     settings this option
     to True, plugin list will be ordered by plugin name.
   @param fixed_list
     (Optional) Override the plugin list with the given plugins.
     Stays until the
     next call with refresh = True.
   @return
     An associative array whose keys and values are the names of all loaded
     plugins.
  """
    php.static(list_, 'list_', {})
    php.static(list_, 'sorted_list')
    if (refresh or fixed_list):
        list_.sorted_list = None
        list_.list_ = {}
        if (fixed_list):
            for name, plugin in fixed_list.items():
                lib_bootstrap.drupal_get_filename('plugin', name,
                                                  plugin['filename'])
                list_.list_[name] = name
        else:
            if (bootstrap):
                result = lib_database.query(\
                  "SELECT name, filename FROM {system} " + \
                  "WHERE type = 'plugin' AND status = 1 AND " + \
                  "bootstrap = 1 ORDER BY weight ASC, filename ASC")
            else:
                result = lib_database.query(\
                  "SELECT name, filename FROM {system} " + \
                  "WHERE type = 'plugin' AND status = 1 " + \
                  "ORDER BY weight ASC, filename ASC")
            while True:
                plugin_ = lib_database.fetch_object(result)
                if (plugin_ == None or plugin_ == False):
                    break
                if (DrupyImport.exists(plugin_.filename)):
                    lib_bootstrap.drupal_get_filename('plugin', \
                      plugin_.name, plugin_.filename)
                    list_.list_[plugin_.name] = plugin_.name
    if (sort):
        if (list_.sorted_list == None):
            list_.sorted_list = plugin_list.list_
            p.ksort(list_.sorted_list)
        return list_.sorted_list
    return list_.list_
Ejemplo n.º 6
0
def column_exists(table, column):
  """
   Check if a column exists in the given table.
  """
  return bool(lib_database.fetch_object(\
    lib_database.query("SHOW COLUMNS FROM {" + \
    lib_database.escape_table(table)  + "} LIKE '" + \
    lib_database.escape_table(column) + "'")))
Ejemplo n.º 7
0
def column_exists(table, column):
    """
   Check if a column exists in the given table.
  """
    return bool(lib_database.fetch_object(\
      lib_database.query("SHOW COLUMNS FROM {" + \
      lib_database.escape_table(table)  + "} LIKE '" + \
      lib_database.escape_table(column) + "'")))
Ejemplo n.º 8
0
def list_(refresh = False, bootstrap = True, sort = False, \
    fixed_list = None):
  """
   Collect a list of all loaded plugins. During the bootstrap, return only
   vital plugins. See bootstrap.inc
  
   @param refresh
     Whether to force the plugin list to be regenerated (such as after the
     administrator has changed the system settings).
   @param bootstrap
     Whether to return the reduced set of plugins loaded in "bootstrap mode"
     for cached pages. See bootstrap.inc.
   @param sort
     By default, plugins are ordered by weight and filename,
     settings this option
     to True, plugin list will be ordered by plugin name.
   @param fixed_list
     (Optional) Override the plugin list with the given plugins.
     Stays until the
     next call with refresh = True.
   @return
     An associative array whose keys and values are the names of all loaded
     plugins.
  """
  php.static(list_, 'list_', {})
  php.static(list_, 'sorted_list')
  if (refresh or fixed_list):
    list_.sorted_list = None
    list_.list_ = {}
    if (fixed_list):
      for name,plugin in fixed_list.items():
        lib_bootstrap.drupal_get_filename('plugin', name, plugin['filename'])
        list_.list_[name] = name
    else:
      if (bootstrap):
        result = lib_database.query(\
          "SELECT name, filename FROM {system} " + \
          "WHERE type = 'plugin' AND status = 1 AND " + \
          "bootstrap = 1 ORDER BY weight ASC, filename ASC")
      else:
        result = lib_database.query(\
          "SELECT name, filename FROM {system} " + \
          "WHERE type = 'plugin' AND status = 1 " + \
          "ORDER BY weight ASC, filename ASC")
      while True:
        plugin_ = lib_database.fetch_object(result)
        if (plugin_ == None or plugin_ == False):
          break
        if (DrupyImport.exists(plugin_.filename)):
          lib_bootstrap.drupal_get_filename('plugin', \
            plugin_.name, plugin_.filename)
          list_.list_[plugin_.name] = plugin_.name
  if (sort):
    if (list_.sorted_list == None):
      list_.sorted_list = plugin_list.list_
      p.ksort(list_.sorted_list)
    return list_.sorted_list
  return list_.list_
Ejemplo n.º 9
0
def get(cid, table = 'cache'):
  """
   Return data from the persistent cache. Data may be stored as either plain 
   text or as serialized data. cache_get will automatically return 
   unserialized objects and arrays.
  
   @param cid
     The cache ID of the data to retrieve.
   @param table
     The table table to store the data in.
     Valid core values are 'cache_filter',
     'cache_menu', 'cache_page', or 'cache' for the default cache.
   @return The cache or FALSE on failure.
  """
  # Garbage collection necessary when enforcing a minimum cache lifetime
  cache_flush = lib_bootstrap.variable_get('cache_flush', 0);
  if (cache_flush and (cache_flush + \
      variable_get('cache_lifetime', 0) <= REQUEST_TIME)):
    # Reset the variable immediately to prevent a meltdown in heavy
    # load situations.
    variable_set('cache_flush', 0);
    # Time to php.flush old cache data
    lib_database.query(\
      "DELETE FROM {" + table + "} WHERE expire != %d AND expire <= %d", \
      CACHE_PERMANENT, cache_flush);
  cache = lib_database.fetch_object(lib_database.query(\
    "SELECT data, created, headers, expire, serialized " + \
    "FROM {" + table + "} WHERE cid = '%s'", cid));
  if (php.isset(cache, 'data')):
    # If the data is permanent or we're not enforcing a minimum cache lifetime
    # always return the cached data.
    if (cache.expire == CACHE_PERMANENT or not \
        variable_get('cache_lifetime', 0)):
      if (cache.serialized):
        cache.data = php.unserialize(cache.data);
    # If enforcing a minimum cache lifetime, validate that the data is
    # currently valid for this user before we return it by making sure the
    # cache entry was created before the timestamp in the current session's
    # cache timer. The cache variable is loaded into the user object by
    # _sess_read() in session.inc.
    else:
      if (lib_appglobals.user.cache > cache.created):
        # This cache data is too old and thus not valid for us, ignore it.
        return False;
      else:
        if (cache.serialized):
          cache.data = php.unserialize(cache.data);
    return cache;
  return False;
Ejemplo n.º 10
0
def get(cid, table='cache'):
    """
   Return data from the persistent cache. Data may be stored as either plain 
   text or as serialized data. cache_get will automatically return 
   unserialized objects and arrays.
  
   @param cid
     The cache ID of the data to retrieve.
   @param table
     The table table to store the data in.
     Valid core values are 'cache_filter',
     'cache_menu', 'cache_page', or 'cache' for the default cache.
   @return The cache or FALSE on failure.
  """
    # Garbage collection necessary when enforcing a minimum cache lifetime
    cache_flush = lib_bootstrap.variable_get('cache_flush', 0)
    if (cache_flush and (cache_flush + \
        variable_get('cache_lifetime', 0) <= REQUEST_TIME)):
        # Reset the variable immediately to prevent a meltdown in heavy
        # load situations.
        variable_set('cache_flush', 0)
        # Time to php.flush old cache data
        lib_database.query(\
          "DELETE FROM {" + table + "} WHERE expire != %d AND expire <= %d", \
          CACHE_PERMANENT, cache_flush)
    cache = lib_database.fetch_object(lib_database.query(\
      "SELECT data, created, headers, expire, serialized " + \
      "FROM {" + table + "} WHERE cid = '%s'", cid))
    if (php.isset(cache, 'data')):
        # If the data is permanent or we're not enforcing a minimum cache lifetime
        # always return the cached data.
        if (cache.expire == CACHE_PERMANENT or not \
            variable_get('cache_lifetime', 0)):
            if (cache.serialized):
                cache.data = php.unserialize(cache.data)
        # If enforcing a minimum cache lifetime, validate that the data is
        # currently valid for this user before we return it by making sure the
        # cache entry was created before the timestamp in the current session's
        # cache timer. The cache variable is loaded into the user object by
        # _sess_read() in session.inc.
        else:
            if (lib_appglobals.user.cache > cache.created):
                # This cache data is too old and thus not valid for us, ignore it.
                return False
            else:
                if (cache.serialized):
                    cache.data = php.unserialize(cache.data)
        return cache
    return False