-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.json.files.php
executable file
·93 lines (79 loc) · 5.34 KB
/
cron.json.files.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require __DIR__ . DIRECTORY_SEPARATOR . 'mainfile.php';
ini_set('memory_limit', '128M');
chdir(API_FONTS_JSON);
echo shell_exec('svn cleanup');
echo shell_exec('svn update');
list($count) = $GLOBALS['APIDB']->fetchRow($GLOBALS['APIDB']->queryF("SELECT COUNT(*) FROM `fonts` WHERE `processed` > '0' AND `stored` > '0' AND `tagged` > '0'"));
if ($count != 0) {
$result = $GLOBALS['APIDB']->queryF("SELECT `id`, `sourceid`, `key` FROM `fonts` WHERE `processed` > '0' AND `stored` > '0' AND `tagged` > '0'");
$keys = $sources = array();
while($font = $GLOBALS['APIDB']->fetchArray($result)) {
$keys[$font['id']] = $font['key'];
$sources[$font['sourceid']] = $font['id'];
}
$result = $GLOBALS['APIDB']->queryF("SELECT DISTINCT `alpha` FROM `fonts` WHERE `processed` > '0' AND `stored` > '0' AND `tagged` > '0'");
$alphas = array();
while($font = $GLOBALS['APIDB']->fetchArray($result))
$alphas[] = $font['alpha'];
sort($alphas);
$result = $GLOBALS['APIDB']->queryF("SELECT DISTINCT `alpha`, `beta` FROM `fonts` WHERE `processed` > '0' AND `stored` > '0' AND `tagged` > '0'");
$betas = array();
while($font = $GLOBALS['APIDB']->fetchArray($result))
$betas[$font['alpha']][] = $font['beta'];
$result = $GLOBALS['APIDB']->queryF("SELECT DISTINCT `beta`, `charley` FROM `fonts` WHERE `processed` > '0' AND `stored` > '0' AND `tagged` > '0'");
$charleys = array();
while($font = $GLOBALS['APIDB']->fetchArray($result))
$charleys[$font['beta']][] = $font['charley'];
foreach(array('files') as $type) {
if (!is_dir(API_FONTS_JSON . DS . $type))
mkdir(API_FONTS_JSON . DS . $type, 0777, true);
foreach($alphas as $alpha) {
if (!is_dir(API_FONTS_JSON . DS . $type . DS . $alpha))
mkdir(API_FONTS_JSON . DS . $type . DS . $alpha, 0777, true);
foreach($betas[$alpha] as $beta) {
if (!is_dir(API_FONTS_JSON . DS . $type . DS . $alpha . DS . $beta))
mkdir(API_FONTS_JSON . DS . $type . DS . $alpha . DS . $beta, 0777, true);
}
}
}
$structure = array();
foreach($alphas as $alpha) {
foreach($betas[$alpha] as $beta) {
foreach($charleys[$beta] as $charley) {
echo "FILES: Alpha = $alpha; Beta = $beta; Charley = $charley\n";
$sql = "SELECT `a`.`key` as `key`, `b`.`filename` as `filename`, `b`.`path` as `path`, `b`.`extension` as `extension`, `b`.`sha1` as `sha1`, `b`.`md5` as `md5`, `b`.`bytes` as `bytes` FROM `fonts` as `a` INNER JOIN `files` as `b` ON `a`.`id` = `b`.`fontid` WHERE `a`.`id` IN (" .implode(", ", array_keys($keys)) . ") AND `a`.`alpha` = '$alpha' AND `a`.`beta` = '$beta' AND `a`.`charley` = '$charley'";
$records = 0;
$files = array();
$result = $GLOBALS['APIDB']->queryF($sql);
while($file = $GLOBALS['APIDB']->fetchArray($result)) {
$files[$file['$key']][$file['filename']] = $file;
$records++;
}
file_put_contents($jfile = API_FONTS_JSON . DS . 'files' . DS . $alpha . DS . $beta . DS . "files.$charley.json", json_encode($files));
$structure[md5_file($jfile)] = array('bytes' => filesize($jfile), 'records' => $records, 'path' => "/json/files/$alpha/$beta", 'filename' => basename($jfile), 'meter' => $charley, 'type' => 'files');
}
}
}
}
file_put_contents($jfile = API_FONTS_JSON . DS . "files.structures.json", json_encode($structure));
file_put_contents($jfile = API_FONTS_JSON . DS . "structures.json", json_encode(array_merge(json_decode(file_get_contents(API_FONTS_JSON . DS . "fonts.structures.json"), true),
json_decode(file_get_contents(API_FONTS_JSON . DS . "glyphs.structures.json"), true),
json_decode(file_get_contents(API_FONTS_JSON . DS . "files.structures.json"), true),
json_decode(file_get_contents(API_FONTS_JSON . DS . "tags.structures.json"), true),
json_decode(file_get_contents(API_FONTS_JSON . DS . "others.structures.json"), true))));
chdir(API_FONTS_JSON);
/*
echo shell_exec('svn add * --force');
foreach(array('files') as $type) {
foreach($alphas as $alpha) {
foreach($betas[$alpha] as $beta) {
if (is_dir(API_FONTS_JSON . DS . $type . DS . $alpha . DS . $beta)) {
chdir(API_FONTS_JSON . DS . $type . DS . $alpha . DS . $beta);
echo shell_exec(sprintf("svn commit -m '%s'", ucfirst($type) ." Data '/fonts/$alpha/$beta/*.json' ~ JSON Resources: ". date('Y/m/d D H:i:s').''));
sleep(mt_rand(7,19));
}
}
}
}
*/