[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Pear/DB/docs/ -> migrateDB.txt (source)

   1  # $Id: migrateDB.txt,v 1.2 2003/10/07 00:11:28 datenpunk Exp $
   2  #
   3  # Short guide on how to migrate a < 1.3 tree to 1.3+
   4  #
   5  # @author       Daniel Khan <dk@webcluster.at>
   6  # @package      DB_NestedSet
   7  # @version      $Revision: 1.2 $
   8  
   9  1. Backup your data!!!
  10  
  11  2. Create a copy of your current node table (copy only the structure).
  12     Maybe you want to add an integer column to tb_nodes2 which will contain
  13     the magic parent field (gains some performance).
  14     Let's call it PARENT. Don't forget to set it inside $params afterwards
  15     Now you should have something like tb_nodes1 and tb_nodes2.
  16     tb_nodes2 is empty for now.
  17  3. Create a DB_NestedSet instance for each table:
  18  
  19  <?php
  20  $params = array(
  21  "STRID"         =>      "id",      // "id" must exist
  22  "ROOTID"        =>      "rootid",  // "rootid" must exist
  23  "l"             =>      "l",       // "l" must exist
  24  "r"             =>      "r",       // "r" must exist
  25  "STREH"         =>      "norder",  // "order" must exist
  26  "LEVEL"         =>      "level",   // "level" must exist
  27  "STRNA"         =>      "name"     // Custom - specify as many fields you want
  28  );
  29  
  30  $params2 = array(
  31  "STRID"         =>      "id",      // "id" must exist
  32  "ROOTID"        =>      "rootid",  // "rootid" must exist
  33  "l"             =>      "l",       // "l" must exist
  34  "r"             =>      "r",       // "r" must exist
  35  "STREH"         =>      "norder",  // "order" must exist
  36  "LEVEL"         =>      "level",   // "level" must exist
  37  "STRNA"         =>      "name",     // Custom - specify as many fields you want
  38  "PARENT"        =>      "parent"    // Not needed but recommended!!!
  39  );
  40  
  41  $db_driver = 'DB';
  42  $db_dsn    = 'mysql://user:password@localhost/test';
  43  $NeSe = DB_NestedSet::factory($db_driver, $db_dsn, $params);
  44  $NeSe->setAttr(array
  45  (
  46  'node_table' => 'tb_nodes',
  47  'lock_table' => 'tb_locks',
  48  'lockTTL'    => 1,
  49  'debug' => 0)
  50  );
  51  
  52  $NeSe2 = DB_NestedSet::factory($db_driver, $db_dsn, $params2);
  53  $NeSe2->setAttr(array
  54  (
  55  'node_table' => 'tb_nodes2', // Note the difference - it's tb_nodes2
  56  'lock_table' => 'tb_locks',
  57  'lockTTL'    => 1,
  58  'debug' => 0)
  59  );
  60  
  61  4. Now pass this 2 objects to the static method convertTreeModel();
  62     DB_NestedSet::convertTreeModel($NeSe, $NeSe2);
  63  
  64  5. Now tb_nodes2 should be filled with a new representation of tb_nodes.
  65  
  66  6. Verify that the row count didn't change and that everything's O.K.
  67  
  68  7. Be happy with your new 1.3+ table.
  69  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7