[ Index ] |
|
Code source de Horde 3.1.3 |
1 #!/usr/bin/php -q 2 <?php 3 /** 4 * $Horde: horde/scripts/upgrades/move_history_out_of_datatree.php,v 1.3.2.1 2005/10/18 11:34:01 jan Exp $ 5 * 6 * This is a script to migrate History information out of the datatree 7 * tables and into its own database table. 8 */ 9 10 // Find the base file path of Horde. 11 @define('AUTH_HANDLER', true); 12 @define('HORDE_BASE', dirname(__FILE__) . '/../..'); 13 14 // Do CLI checks and environment setup first. 15 require_once HORDE_BASE . '/lib/core.php'; 16 require_once 'Horde/CLI.php'; 17 18 // Make sure no one runs this from the web. 19 if (!Horde_CLI::runningFromCLI()) { 20 exit("Must be run from the command line\n"); 21 } 22 23 // Load the CLI environment - make sure there's no time limit, init 24 // some variables, etc. 25 Horde_CLI::init(); 26 $cli = Horde_CLI::singleton(); 27 28 $cli->writeln($cli->yellow("Beginning migration. This may take a very long time to complete.")); 29 $cli->writeln(); 30 31 require_once HORDE_BASE . '/lib/base.php'; 32 require_once 'Horde/DataTree.php'; 33 34 class DataTreeObject_History extends DataTreeObject { 35 36 function _fromAttributes($attributes) 37 { 38 /* Initialize data array. */ 39 $this->data = array(); 40 41 foreach ($attributes as $attr) { 42 if (!isset($this->data[$attr['name']])) { 43 $this->data[$attr['name']] = array(); 44 } 45 $this->data[$attr['name']][$attr['key']] = $attr['value']; 46 } 47 } 48 49 } 50 51 $datatree = &DataTree::factory('sql', array_merge(Horde::getDriverConfig('datatree', 'sql'), 52 array('group' => 'horde.history'))); 53 $db = &$datatree->_db; 54 55 $isql = 'INSERT INTO horde_histories (history_id, object_uid, history_action, history_desc, history_who, history_ts, history_extra)' . 56 ' VALUES (?, ?, ?, ?, ?, ?, ?)'; 57 58 $all = $datatree->get(DATATREE_FORMAT_FLAT, DATATREE_ROOT, true); 59 unset($all[DATATREE_ROOT]); 60 $ids = array_keys($all); 61 62 foreach ($ids as $id) { 63 $ob = $datatree->getObjectById($id, 'DataTreeObject_History'); 64 foreach ($ob->getData() as $row) { 65 $values = array($db->nextId('horde_histories'), // history_id 66 $ob->getName(), // object_uid 67 isset($row['action']) ? $row['action'] : null, // history_action 68 isset($row['desc']) ? $row['desc'] : null, // history_desc 69 isset($row['who']) ? $row['who'] : null, // history_who 70 isset($row['ts']) ? $row['ts'] : null, // history_ts 71 ); 72 73 unset($row['action']); 74 unset($row['desc']); 75 unset($row['who']); 76 unset($row['ts']); 77 if (count($row)) { 78 $values[] = serialize($row); // history_extra 79 } else { 80 $values[] = null; // history_extra 81 } 82 83 check($db->query($isql, $values)); 84 } 85 86 check($db->query('DELETE FROM horde_datatree_attributes WHERE datatree_id = ?', array($id))); 87 check($db->query('DELETE FROM horde_datatree WHERE datatree_id = ?', array($id))); 88 } 89 90 $cli->writeln($cli->green("Done. Migrated " . count($ids) . " objects.")); 91 92 function check($result) 93 { 94 if (is_a($result, 'PEAR_Error')) { 95 var_dump($result); 96 exit; 97 } 98 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |