[ansel] CLI script for setting date-uploaded

Heath S. Hendrickson heath at outerspaceconsultants.com
Tue May 18 22:09:38 PDT 2004


Attached is another CLI script that will set the date-uploaded to the 
date value for all images in Ansel that have a date attribute set.

h


-------------- next part --------------
#!/usr/local/bin/php
<?php
/**
 * $Horde: ansel/scripts/fix_paths_vfs_sql.php,v 1.6 2004/01/24 20:04:32 chuck Exp $
 *
 * This is a script to set the value stored in the date-uploaded attribute
 *  based on the value in the 
 */

/**
 ** Set this to true if you want DB inserts done.
 **/
$live = false;

@define('AUTH_HANDLER', true);
@define('ANSEL_BASE', dirname(__FILE__) . '/..');
@define('HORDE_BASE', ANSEL_BASE . '/..');

// Do CLI checks and environment setup first.
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");
}

// Load the CLI environment - make sure there's no time limit, init
// some variables, etc.

require_once ANSEL_BASE . '/lib/base.php';
require_once 'Horde/Share.php';
Horde_CLI::init();

Horde_CLI::init();
$cli = &Horde_CLI::singleton();
$registry = &Registry::singleton();
$registry->pushApp('ansel', false);
$shares = &Horde_Share::singleton($registry->getApp());

$crit['AND'] = array( array('field' => 'name', 'op' => '=', 'test' => 'date'),
                      array('field' => 'value', 'op' => 'LIKE', 'test' => '%'));

$images = &$ansel_shares->searchAllImages($crit);

$count = 0;
echo "Found " . count($images) . " images\n";
foreach ($images as $id => $name) {
   unset($image);
   $image = &$ansel_shares->getImage($name);
   $timeVal = $image->get('date');
   if (!empty($timeVal)) {
      $count++;
      echo "$count: $id => $timeVal = " . date('Y-m-d h:i:s O', $timeVal) . "\n";
      if ($live) {
         $image->set('date-uploaded', date("Y-m-d h:i:s O", $timeVal), true);
      }
   }
}

if ($live) {
    echo $count . " row(s) updated.\n";
} else {
    echo $count . " row(s) would have been updated.\n";
}


More information about the ansel mailing list