-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremetadata.php
More file actions
69 lines (47 loc) · 1.65 KB
/
remetadata.php
File metadata and controls
69 lines (47 loc) · 1.65 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
use WebFetchFace\DbConnection;
use WebFetchFace\DownloadStatus;
require_once __DIR__ . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'functions.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoloader.php';
// TODO: refactor
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$tmpDir = __DIR__ . DIRECTORY_SEPARATOR . $relDir;
$db = new DbConnection($filesDb);
$result = $db->query('SELECT Id,ThumbFileName FROM files WHERE MetadataFileName IS NULL ORDER BY Id DESC');
$changedFiles = 0;
$toDownload = array();
$prepThumbnail = $db->prepare('UPDATE files SET MetadataFileName=? WHERE Id=?');
foreach ($result as $row) {
$thumbPath = dirname($row['ThumbFileName']);
$thumbFileName = basename($row['ThumbFileName']);
$id = $row['Id'];
if (!$thumbFileName || !file_exists($row['ThumbFileName'])) {
echo "no thumbnail: $id\n";
continue;
}
$jsonFileName = dirname($row['ThumbFileName']) . '/' . $row['Id'] . '.json';
if ($jsonFileName && file_exists($jsonFileName)) {
$prepThumbnail->execute(array($jsonFileName, $id));
} else {
echo "cannot update $id\n";
}
}
$result = $db->query('SELECT Id,MetadataFileName FROM files WHERE DisplayId IS NULL AND MetadataFileName IS NOT NULL ORDER BY Id DESC');
$changedFiles = 0;
$toDownload = array();
$prepDisplayId = $db->prepare('UPDATE files SET DisplayId=? WHERE Id=?');
foreach ($result as $row) {
$id = $row['Id'];
$data = getJsonFile($row['MetadataFileName']);
if (!$data) {
echo "Not found: $id";
}
$did = getDisplayId($data);
if ($did != '') {
$prepDisplayId->execute(array($did, $id));
} else {
echo "cannot update $id\n";
}
}