[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

/scripts/ -> migrate_user_categories.php (source)

   1  #!/usr/bin/php -q
   2  <?php
   3  /**
   4   * $Horde: horde/scripts/migrate_user_categories.php,v 1.5.10.1 2005/10/18 11:34:00 jan Exp $
   5   *
   6   * A script to update users preferences to combine their categories
   7   * and category colors from Genie, Kronolith, Mnemo, and Nag into the
   8   * new Horde-wide preferences. Expects to be given a list of users on
   9   * STDIN, one username per line, to convert. Usernames need to match
  10   * the values stored in the preferences backend.
  11   */
  12  
  13  // Find the base file path of Horde.
  14  @define('AUTH_HANDLER', true);
  15  @define('HORDE_BASE', dirname(__FILE__) . '/..');
  16  
  17  // Do CLI checks and environment setup first.
  18  require_once  HORDE_BASE . '/lib/core.php';
  19  require_once  'Horde/CLI.php';
  20  
  21  // Make sure no one runs this from the web.
  22  if (!Horde_CLI::runningFromCLI()) {
  23      exit("Must be run from the command line\n");
  24  }
  25  
  26  // Load the CLI environment - make sure there's no time limit, init
  27  // some variables, etc.
  28  Horde_CLI::init();
  29  
  30  require_once  HORDE_BASE . '/lib/base.php';
  31  require_once  'Horde/Prefs/CategoryManager.php';
  32  $cli = &Horde_CLI::singleton();
  33  $auth = &Auth::singleton($conf['auth']['driver']);
  34  $cManager = &new Prefs_CategoryManager();
  35  $apps = $registry->listApps(array('hidden', 'notoolbar', 'active', 'admin'));
  36  
  37  // Read in the list of usernames on STDIN.
  38  $users = array();
  39  while (!feof(STDIN)) {
  40      $line = fgets(STDIN);
  41      $line = trim($line);
  42      if (!empty($line)) {
  43          $users[] = $line;
  44      }
  45  }
  46  
  47  // Loop through users and convert prefs for Genie, Mnemo, Nag, and
  48  // Kronolith.
  49  foreach ($users as $user) {
  50      echo 'Migrating prefs for ' . $cli->bold($user);
  51  
  52      // Set $user as the current user.
  53      $auth->setAuth($user, array(), '');
  54  
  55      // Fetch current categories and colors.
  56      $colors = $cManager->colors();
  57  
  58      // Genie.
  59      if (in_array('genie', $apps)) {
  60          echo ' . genie';
  61          $result = $registry->pushApp('genie', false);
  62          if (!is_a($result, 'PEAR_Error')) {
  63              $g_categories = listCategories('wish_categories');
  64              foreach ($g_categories as $category) {
  65                  $cManager->add($category);
  66              }
  67          }
  68      }
  69  
  70      // Mnemo.
  71      if (in_array('mnemo', $apps)) {
  72          echo ' . mnemo';
  73          $result = $registry->pushApp('mnemo', false);
  74          if (!is_a($result, 'PEAR_Error')) {
  75              $m_categories = listCategories('memo_categories');
  76              $m_colors = listColors('memo_colors');
  77              foreach ($m_categories as $key => $category) {
  78                  if (isset($m_colors[$key])) {
  79                      $colors[$category] = $m_colors[$key];
  80                  }
  81                  $cManager->add($category);
  82              }
  83          }
  84      }
  85  
  86      // Nag.
  87      if (in_array('nag', $apps)) {
  88          echo ' . nag';
  89          $result = $registry->pushApp('nag', false);
  90          if (!is_a($result, 'PEAR_Error')) {
  91              $n_categories = listCategories('task_categories');
  92              foreach ($n_categories as $category) {
  93                  $cManager->add($category);
  94              }
  95          }
  96      }
  97  
  98      // Kronolith.
  99      if (in_array('kronolith', $apps)) {
 100          echo ' . kronolith';
 101          $result = $registry->pushApp('kronolith', false);
 102          if (!is_a($result, 'PEAR_Error')) {
 103              $k_categories = listCategories('event_categories');
 104              if (count($k_categories)) var_dump($k_categories);
 105              $k_colors = listColors('event_colors');
 106              foreach ($k_categories as $key => $category) {
 107                  if (isset($k_colors[$key])) {
 108                      $colors[$category] = $k_colors[$key];
 109                  }
 110                  $cManager->add($category);
 111              }
 112          }
 113      }
 114  
 115      $cManager->setColors($colors);
 116      $prefs->store();
 117      $cli->writeln();
 118  }
 119  
 120  $cli->writeln();
 121  $cli->writeln($cli->green('DONE'));
 122  exit;
 123  
 124  function listCategories($prefname)
 125  {
 126      global $prefs;
 127  
 128      $string = $prefs->getValue($prefname);
 129      if (empty($string)) {
 130          return array();
 131      }
 132  
 133      $cats = explode('|', $string);
 134      foreach ($cats as $cat) {
 135          list($key, $val) = explode(':', $cat);
 136          $categories[$key] = $val;
 137      }
 138  
 139      return $categories;
 140  }
 141  
 142  function listColors($prefname)
 143  {
 144      global $prefs;
 145  
 146      $string = $prefs->getValue($prefname);
 147      if (empty($string)) {
 148          return array();
 149      }
 150      $cols = explode('|', $string);
 151      $colors = array();
 152      foreach ($cols as $col) {
 153          list($key, $val) = explode(':', $col);
 154          $colors[$key] = $val;
 155      }
 156  
 157      return $colors;
 158  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7