LiveUser
[ class tree: LiveUser ] [ index: LiveUser ] [ all elements ]

Source for file install.php

Documentation is available at install.php

  1. <?php
  2.  
  3. // $file is the name of the schema to be inserted into the database
  4. // $config
  5.  
  6. require_once 'LiveUser.php';
  7. require_once 'MDB2.php';
  8. MDB2::loadFile('Tools/Manager');
  9.  
  10. /*
  11. $dsn = 'mysql://root:@localhost/liveuser_test_installer';
  12.  
  13. $conf = array(
  14.     'authContainers' => array(
  15.         array(
  16.             'type'          => 'DB',
  17.             'dsn'           => $dsn,
  18.             'authTable'     => 'liveuser_users',
  19.             'authTableCols' => array(
  20.                 'required'  => array(
  21.                     'auth_user_id' => array('name' => 'authUserId', 'type' => 'text'),
  22.                     'handle'       => array('name' => 'handle',     'type' => 'text'),
  23.                     'passwd'       => array('name' => 'passwd',     'type' => 'text'),
  24.                 ),
  25.                 'optional' => array(
  26.                     'lastlogin'    => array('name' => 'lastLogin',  'type' => 'timestamp'),
  27.                     'is_active'    => array('name' => 'isActive',   'type' => 'boolean')
  28.                 ),
  29.             ),
  30.         ),
  31.     ),
  32.     'permContainer'  => array(
  33.         'type'  => 'Complex',
  34.         'storage' => array('DB' => array('dsn' => $dsn, 'prefix'     => 'liveuser_')),
  35.     )
  36. );
  37.  
  38. $installer =& new LiveUser_Misc_Schema_Install();
  39. $result = $installer->installAuthSchema($conf['authContainers'][0], 'auth_mdb_schema.xml', true);
  40. var_dump($result);
  41. $result = $installer->installPermSchema($conf['permContainer']['storage']['DB'], 'perm_mdb_schema.xml', false);
  42. var_dump($result);
  43. */
  44.  
  45. class LiveUser_Misc_Schema_Install
  46. {
  47.     function installAuthSchema($config$file$create = true)
  48.     {
  49.         if (isset($config['connection'])) {
  50.             $dsn $config['connection']->dsn;
  51.             if (!isset($dsn['database'])) {
  52.                 $dsn['database'$config['connection']->database_name;
  53.             }
  54.         else {
  55.             $dsn = MDB2::parseDSN($config['dsn']);
  56.         }
  57.  
  58.         $variables = array('database' => $dsn['database']);
  59.  
  60.         $variables['user_table_name'= isset($config['authTable'])
  61.             ? $config['authTable''liveuser_users';
  62.         $variables['auth_user_id_name'= isset($config['authTableCols']['required']['auth_user_id']['name'])
  63.             ? $config['authTableCols']['required']['auth_user_id']['name''auth_user_id';
  64.         $variables['handle_name'= isset($config['authTableCols']['required']['handle']['name'])
  65.             ? $config['authTableCols']['required']['handle']['name''handle';
  66.         $variables['passwd_name'= isset($config['authTableCols']['required']['passwd']['name'])
  67.             ? $config['authTableCols']['required']['passwd']['name''passwd';
  68.         $variables['lastlogin_name'= isset($config['authTableCols']['optional']['lastlogin']['name'])
  69.             ? $config['authTableCols']['optional']['lastlogin']['name''lastlogin';
  70.         $variables['is_active_name'= isset($config['authTableCols']['optional']['is_active']['name'])
  71.             ? $config['authTableCols']['optional']['is_active']['name''is_active';
  72.         $variables['owner_user_id_name'= isset($config['authTableCols']['custom']['owner_user_id']['name'])
  73.             ? $config['authTableCols']['custom']['owner_user_id']['name''owner_user_id';
  74.         $variables['owner_group_id_name'= isset($config['authTableCols']['custom']['owner_group_id']['name'])
  75.             ? $config['authTableCols']['custom']['owner_group_id']['name''owner_group_id';
  76.  
  77.         return $this->installSchema($dsn$file$variables$create);
  78.     }
  79.  
  80.     function installPermSchema($config$file$create = true)
  81.     {
  82.         if (isset($config['connection'])) {
  83.             $dsn $config['connection']->dsn;
  84.             if (!isset($dsn['database'])) {
  85.                 $dsn['database'$config['connection']->database_name;
  86.             }
  87.         else {
  88.             $dsn = MDB2::parseDSN($config['dsn']);
  89.         }
  90.  
  91.         $variables = array(
  92.             'database' => $dsn['database'],
  93.             'table_prefix' => $config['prefix'],
  94.             'right_max_level' => LIVEUSER_MAX_LEVEL,
  95.         );
  96.  
  97.         return $this->installSchema($dsn$file$variables);
  98.     }
  99.  
  100.     function installSchema($dsn$file$variables$create = true)
  101.     {
  102.         $manager =new MDB2_Tools_Manager;
  103.  
  104.         unset($dsn['database']);
  105.  
  106.         $options = array(
  107.             'debug' => true,
  108.             'log_line_break' => '<br>',
  109.             'portability' => (MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL),
  110.         );
  111.  
  112.         $err $manager->connect($dsn$options);
  113.         if (MDB2::isError($err)) {
  114.             return $err->getMessage().' - '.$err->getUserinfo();
  115.         }
  116.  
  117.         $variables['create'= (int)$create;
  118.         $result $manager->updateDatabase($file'old_'.$file$variables);
  119.         echo('Debug messages<br>');
  120.         echo($manager->db->debugOutput().'<br>');
  121.  
  122.         $manager->disconnect();
  123.         return $result;
  124.     }
  125. }
  126.  
  127. ?>

Documentation generated on Mon, 11 Mar 2019 14:31:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.