[ansel] lib/Gallery.php patch for date-uploaded change
Heath S. Hendrickson
heath at outerspaceconsultants.com
Tue May 18 20:37:54 PDT 2004
Heath S. Hendrickson wrote:
> Attached is a patch that sets the date-uploaded to be the RFC date
> representation (date("r")) instead of the epoch (time()).
>
> This makes the field useful for searches.
>
And here's a CLI script that will update any images that have the time()
form stored in date-uploaded. It should be safe to use on images that
already use the new format (I threw in a QnD check to make sure it was
the time() format only that was getting changed) and it even prints out
what it's doing so you know that it's working okay (run with live=false
to test before doing anything).
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 fix the value stored in the date-uploaded attribute
*/
/**
** Set this to true if you want DB inserts done.
**/
$live = true;
@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-uploaded'),
array('field' => 'value', 'op' => '!=', 'test' => ''));
$images = &$ansel_shares->searchAllImages($crit);
$count = 0;
foreach ($images as $id => $name) {
$image = &$ansel_shares->getImage($name);
$timeVal = $image->get('date-uploaded');
if (!strstr($timeVal, ",")){
$count++;
echo "$count: $id => $timeVal = " . date('r', $timeVal) . "\n";
if ($live) {
$image->data['date-uploaded'] = date("r", $timeVal);
}
}
}
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