Skip to content

Commit

Permalink
fix_sizes script
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Feb 9, 2010
1 parent 9dd3fd0 commit 278906d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README
Expand Up @@ -19,6 +19,10 @@ creates a tree of installations suitable for unit testing (one install for
each combination of stable/dev and mysql/pgsql/sqlite, with wipe-and-reinstall
scripts to clean up after testing)

fix_sizes.php
~~~~~~~~~~~~~
Fix the database in cases where the height/width/filesize were listed as zero

cli_import.php [OLD]
~~~~~~~~~~~~~~~~~~~~
Like the "bulk add" extension, but works from the command line.
Expand Down
47 changes: 47 additions & 0 deletions fix_sizes.php
@@ -0,0 +1,47 @@
<?php
require_once "config.php";
require_once "lib/adodb/adodb.inc.php";

$db = NewADOConnection($database_dsn);
$db->SetFetchMode(ADODB_FETCH_ASSOC);

$result = $db->Execute("SELECT * FROM images WHERE width=0 AND height=0");
while(!$result->EOF) {
$fields = $result->fields;

$id = $fields['id'];
$hash = $fields['hash'];
$ext = $fields['ext'];
$ab = substr($hash, 0, 2);
$fname = "images/$ab/$hash";

$info = getimagesize($fname);
if($info) {
$width = $info[0];
$height = $info[1];

print "{$id} ($fname): {$width}x{$height}\n";
$db->Execute("UPDATE images SET width=?, height=? WHERE id=?", array($width, $height, $id));
}

$result->MoveNext();
}

$result = $db->Execute("SELECT * FROM images WHERE filesize=0");
while(!$result->EOF) {
$fields = $result->fields;

$id = $fields['id'];
$hash = $fields['hash'];
$ext = $fields['ext'];
$ab = substr($hash, 0, 2);
$fname = "images/$ab/$hash";

$size = filesize($fname);
print "{$id} ($fname): {$size}\n";
$db->Execute("UPDATE images SET filesize=? WHERE id=?", array($size, $id));

$result->MoveNext();
}

?>

0 comments on commit 278906d

Please sign in to comment.