Created
June 13, 2011 22:18
-
-
Save wojtha/1023869 to your computer and use it in GitHub Desktop.
Drupal snippet - report missing files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$purge = FALSE; | |
$result = db_query('SELECT fid, filename, filepath FROM {files}'); | |
$i = 1; | |
$out = "MISSING FILES:\n"; | |
while ($f = db_fetch_object($result)) { | |
$dest = file_create_path($f->filepath); | |
if (!file_exists($dest)) { | |
$out .= $i++ . '. ' . $f->filepath; | |
if ($purge) { | |
if (db_query('DELETE FROM {files} WHERE fid=%d', $f->fid)) { | |
$out .= ' (cleaned)'; | |
} | |
} | |
$out .= "\n"; | |
} | |
} | |
if ($i == 1) { | |
$out .= "Congratulation, no file is missing!\n"; | |
} | |
return $out; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment