forked from standardebooks/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-ebook-database
executable file
·62 lines (50 loc) · 1.58 KB
/
update-ebook-database
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
#!/usr/bin/php
<?
require_once('/standardebooks.org/web/lib/Core.php');
use function Safe\getopt;
$longopts = ['ebook-www-filesystem-path:', 'verbose'];
$options = getopt('v', $longopts);
$ebookWwwFilesystemPath = $options['ebook-www-filesystem-path'] ?? null;
$verbose = false;
if(isset($options['v']) || isset($options['verbose'])){
$verbose = true;
}
if($ebookWwwFilesystemPath === null){
print("Expected usage: update-ebook-database [-v,--verbose] --ebook-www-filesystem-path <path>\n");
exit(1);
}
if($verbose){
print("ebook-www-filesystem-path: $ebookWwwFilesystemPath\n");
}
try{
$ebook = Ebook::FromFilesystem($ebookWwwFilesystemPath);
}
catch(Exceptions\AppException $appException){
print("An AppException occurred when updating the ebook database:\n");
print("\t" . get_class($appException) . ": " . $appException->getMessage() . "\n");
exit(1);
}
if($verbose){
print("Title: $ebook->Title\n");
print("Identifier: $ebook->Identifier\n");
}
try{
$ebook->CreateOrUpdate();
}
catch(Exceptions\ValidationException $validationException){
$exceptions = $validationException->Exceptions;
if(count($exceptions) == 1){
print("\nA ValidationException occurred when updating the ebook database:\n");
print("\t" . get_class($exceptions[0]) . ": " . $exceptions[0]->getMessage() . "\n");
print("[ERROR] Found 1 error\n");
}
else{
print("\nValidationExceptions when updating the ebook database:\n");
foreach($exceptions as $ex){
print("\t" . get_class($ex) . ": " . $ex->getMessage() . "\n");
}
print("[ERROR] Found " . count($exceptions) . " errors\n");
}
exit(1);
}
exit(0);