[ansel] lib/Gallery.php patch for date-uploaded change

Heath S. Hendrickson heath at outerspaceconsultants.com
Tue May 18 21:00:01 PDT 2004


Chuck Hagenbuch wrote:

> date('r') isn't really optimal for searches, either. I'd much rather 
> see it be
> stored as YYYY-MM-DD HH:MM:SS. That way it's both searchable, 
> sortable, and
> easily turned into a timestamp/formatted other ways.
>
ok.  attached is a new patch that uses date("Y-m-d h:i:s O").

Also attached is a new script that will convert from timecode based 
values to the new format.

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 = 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-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');
   $count++;
   if (strstr($timeVal, ",")){
      $timecode = strtotime($timeVal);
   } else {
      $timecode = $timeVal;
   }
   echo "$count: $id => $timeVal = " . date('Y-m-d h:i:s O', $timecode) . "\n";
   if ($live) {
        $image->set('date-uploaded', date("Y-m-d h:i:s O", $timecode), true);
   }
}

if ($live) {
    echo $count . " row(s) updated.\n";
} else {
    echo $count . " row(s) would have been updated.\n";
}
-------------- next part --------------
Index: lib/Gallery.php
===================================================================
RCS file: /usr/local/horde/cvs/ansel/lib/Gallery.php,v
retrieving revision 1.61
diff -u -r1.61 Gallery.php
--- lib/Gallery.php	17 May 2004 21:49:02 -0000	1.61
+++ lib/Gallery.php	19 May 2004 03:57:52 -0000
@@ -531,7 +531,7 @@
         $this->_image->reset();
 
         $this->data['gallery'] = '-1';
-        $this->data['date-uploaded'] = time();
+        $this->data['date-uploaded'] = date("Y-m-d h:i:s O");
 
         if (is_array($image)) {
             $this->data['filename'] = $image['filename'];


More information about the ansel mailing list