123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?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;
- }
|