[cvs] [Wiki] changed: DatabaseCleanup

Wiki Guest wikiguest at horde.org
Thu Jan 29 16:05:06 UTC 2009


guest [193.50.125.9]  Thu, 29 Jan 2009 11:05:06 -0500

Modified page: http://wiki.horde.org/DatabaseCleanup
New Revision:  1.5
Change log:  better explain the script

@@ -1,7 +1,10 @@
  January 12th 2009
-Another script in PHP using API removeUserData dom.lalot à gmail.com
-Sorry for my poor coding, I'm a Perl programmer not a PHP one.
+Another script in PHP using API removeUserData from dom.lalot à gmail.com
+Sorry for my poor coding, I'm a Perl programmer not a PHP one. The  
purpose of this script is to remove data from non existent users. Your  
auth driver should be able to listusers. The prefs are analyzed to get  
all current entries by checking uid. Then we compare to the list of  
all current users.
+You have to change the script to get it working. There an exit before  
doing the bad job.
+
+Save you data if you have some fears.

  <code>
  #!/usr/bin/env php
  <?php
@@ -12,9 +15,9 @@
  require_once HORDE_BASE . '/lib/core.php';
  require_once 'Horde/CLI.php';
  // Make sure no one runs this from the web.
  if (!Horde_CLI::runningFromCLI()) {
-    exit("Must be run from the command line\n");
+    exit("Must be run from the command linen");
  }
  // Load the CLI environment - make sure there's no time limit, init some
  // variables, etc.
  $cli = &Horde_CLI::singleton();
@@ -22,9 +25,9 @@
  // Include needed libraries.
  require_once HORDE_BASE . '/lib/base.php';
  // Authenticate as administrator.
  if (!count($conf['auth']['admins'])) {
-    exit("You must have at least one administrator configured to run  
the alarms.php script.\n");
+    exit("You must have at least one administrator configured to run  
the alarms.php script.n");
  }
  $auth = &Auth::singleton($conf['auth']['driver']);
  $auth->setAuth($conf['auth']['admins'][0], array());
  require_once HORDE_BASE . '/lib/Horde/Auth.php';
@@ -36,12 +39,12 @@
  }
  $validusers=$auth->listUsers();
  $valides=count($validusers);
  if ($valides==0){
-   echo "Can't list users, your auth driver has no listusers capability\n";
+   echo "Can't list users, your auth driver has no listusers capabilityn";
     exit;
  }
-echo "$valides valid users found\n";
+echo "$valides valid users foundn";
  $valides=array();
  foreach($validusers as $value){
     $valides[$value]=1;
  }
@@ -58,21 +61,21 @@
     $login=$row['pref_uid'];
      $uid[$login] = $login;
  }
  $total=count($uid);
-echo "$total data user found\n";
-echo "Exit without removing data, change the script please\n";
+echo "$total data user foundn";
+echo "Exit without removing data, change the script pleasen";
  exit; # Drop this line if you want to remove data

  //now compare valid and data found and purge
  foreach ($uid as $value) {
     if (!array_key_exists($value,$valides)){
-      echo "Not Found $value\n";
+      echo "Not Found $valuen";
        Auth::removeUserData($value);
        $supp++;
     }
  }
-echo "suppressed $supp\n";
+echo "suppressed $suppn";
  ?>


  </code>


More information about the cvs mailing list