Browse Source

Preserved 5.x version from 2007-12-25.

Frederic G. MARAND 11 years ago
parent
commit
c0f38a700b
3 changed files with 158 additions and 1 deletions
  1. 0 1
      README
  2. 5 0
      offload.info
  3. 153 0
      offload.module

+ 0 - 1
README

@@ -1 +0,0 @@
-Please use the per-core-version branches, not master.

+ 5 - 0
offload.info

@@ -0,0 +1,5 @@
+; $Id$
+name = Offload
+description = Off-site replication of historical data
+package = High-volume
+version = "$Name:  $"

+ 153 - 0
offload.module

@@ -0,0 +1,153 @@
+<?php
+/**
+ * The offload module allows site admins to prune older data from sites with
+ * heavy workloads in order to maintain performance without having to lose the
+ * historical data. It achieves this result by allowing a non-web back-office
+ * to automatically replicate historical data to a back office database, then
+ * remove the replicated data from the historical table within Drupal.
+ *
+ * By default, the module is configured to work with
+ * - accesslog (from core)
+ * It also works with contrib modules:
+ * - zeitgeist
+ * And potentially any other module using logging tables with a monotone key sequence
+ *
+ * A sample replication client in PHP-GTK is provided in the "client" directory
+ *
+ * (c) 2007 Ouest Systèmes Informatiques.
+ * Licensed under the CeCILL 2.0
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
+ *
+ */
+
+define(OFFLOADVARTABLES, 'offload_tables');
+define(OFFLOADVARIP,     'offload_ip');
+
+define(OFFLOADPERM,      'offload history');
+define(OFFLOADVERSION,   '$Id$');
+
+function offload_help($section)
+  {
+  $ret = null;
+  switch ($section)
+    {
+    case 'admin/help#offload':
+      $ret = t('<p>The offload module allows site admins to prune older data from sites with heavy workloads in order to maintain performance without having to lose the historical data. It achieves this result by allowing a non-web back-office to automatically replicate historical data to a back office database, then remove the replicated data from the historical table within Drupal.</p>');
+      break;
+    }
+  return $ret;
+  }
+
+/*
+ * Implementation of hook_menu().
+ */
+function offload_menu($may_cache)
+  {
+  $items = array();
+
+  if ($may_cache)
+    {
+	$items[] = array(
+      'path'     => 'admin/settings/offload',
+	  'title'    => t('History off-load '),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('offload_settings'),
+      'access'   => user_access(OFFLOADPERM),
+	  );
+	}
+  return $items;
+  }
+
+function offload_perm()
+  {
+  return array
+    (
+    OFFLOADPERM,
+    );
+  }
+
+function offload_settings()
+  {
+  $ar1 = variable_get(OFFLOADVARTABLES, array(
+    array('accesslog', 'aid', NULL)) /* table name, id, highest key offloaded */
+    );
+  $ar2 = array();
+  foreach ($ar1 as $table)
+    {
+    $ar2[] = "{$table[0]} ({$table[1]} = {$table[2]})";
+    }
+
+  $form[OFFLOADVARIP] = array(
+    '#type'          => 'textfield',
+    '#title'         => t('Client IP address'),
+    '#default_value' => variable_get(OFFLOADVARIP, '127.0.0.1'),
+    '#description' => t('The single IP address allowed to use the offload module as a client. Be warned that, in shared hosting situations, the default 127.0.0.1 may <em>not</em> be safe'),
+    );
+
+  $form['info']= array(
+    '#type'  => 'fieldset',
+    '#title' => t('Tables configured for offload'),
+    '#description' => t('In future versions, this will be settable. For now the list is hardcoded'),
+    );
+  $form['info']['tables'] = array(
+    '#type'  => 'markup',
+    '#value' => theme('item_list', $ar2),
+    );
+
+  $form['advanced'] = array(
+    '#type'  => 'fieldset',
+    '#title' => t('Advanced information'),
+    '#collapsible' => TRUE,
+    '#collapsed'   => TRUE,
+    );
+  $form['advanced']['version'] = array(
+    '#type'        => 'markup',
+    '#description' => 'CVS Version',
+    '#value'       => OFFLOADVERSION,
+    '#prefix'      => '<p>',
+    '#suffix'      => '</p><div class="description">CVS Version</div>',
+    );
+
+  return system_settings_form($form);
+  }
+
+function offload_xmlrpc()
+  {
+  return array(
+    'offload.info'         => 'offload_info',
+    'offload.login'        => 'offload_authenticate',
+    'offload.table_status' => 'offload_table_status',
+    );
+  }
+
+function offload_info()
+  {
+  return t('Offload module is alive');
+  }
+
+function offload_authenticate($name, $pass)
+  {
+  $ret = user_authenticate($name, $pass);
+  return $ret;
+  }
+
+function offload_table_status($ar_tables)
+  {
+  global $db_prefix;
+
+  $sq = 'SHOW TABLE STATUS';
+  $q = db_query($sq);
+  $len = strlen($db_prefix);
+  while ($row = db_fetch_array($q))
+    {
+    if (strncmp($row['Name'], $db_prefix, $len) !== 0)
+      continue;
+
+    $name = substr($row['Name'], $len);
+    if (array_key_exists($name, $ar_tables))
+      {
+      $ar_tables[$name]['remote'] = $row['Rows'];
+      }
+    }
+  return $ar_tables;
+  }