-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_missing_media.php
executable file
·50 lines (37 loc) · 1.04 KB
/
find_missing_media.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/php
<?php
if ($argc != 3) {
$help = <<<EOL
Loop through all entries in <importfile>, search for a match in <logfile> and write
all unmatched entries to stdout
Usage:
find_missing_media.php <importfile> <logfile>
<?php
EOL;
// Output help text and exit
file_put_contents('php://stderr', $help);
exit(1);
}
$handle = fopen($argv[1], "r") or die('Could not open '.$argv[1].' for reading');
$stdout = fopen('php://stdout', 'w');
$importLog = file($argv[2], FILE_IGNORE_NEW_LINES) or die('Could not read '.$argv[2]);
// Skip header
$header = fgetcsv($handle, 1000, ",");
while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
$match = false;
// Search on the filename without path
$filename = basename($row[0]);
// Search import log for match
foreach ($importLog as $value) {
// If filename found in import log, exit loop and don't do anything
if (strpos($value, $filename) !== FALSE) {
$match = true;
break;
}
}
// Echo unmatched files
if (!$match) {
echo fputcsv($stdout, $row);
}
}
?>