-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgenerate_thumbnails.php
More file actions
executable file
·123 lines (106 loc) · 3.72 KB
/
Copy pathgenerate_thumbnails.php
File metadata and controls
executable file
·123 lines (106 loc) · 3.72 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env php
<?php
/**
* Generate Missing Thumbnails Script
*
* This script finds images without thumbnails and generates them.
* Can be run manually or via cron job.
*
* Usage:
* php generate_thumbnails.php [options] [system_id]
*
* Options:
* --force-all Force regeneration of all thumbnails (even existing ones)
* --verbose Enable verbose output (default: silent for cron usage)
*
* Arguments:
* system_id (optional) Only process images for this specific system
*
* Examples:
* php generate_thumbnails.php # Generate missing/incomplete thumbnails for all systems (silent)
* php generate_thumbnails.php --verbose # Generate missing/incomplete thumbnails with output
* php generate_thumbnails.php 123 # Generate missing/incomplete thumbnails for system ID 123 (silent)
* php generate_thumbnails.php --force-all # Regenerate ALL thumbnails for all systems (silent)
* php generate_thumbnails.php --verbose --force-all # Regenerate ALL thumbnails with output
*/
// Change to www directory
$dir = dirname(__FILE__);
if(is_dir("/var/www/heatpumpmonitororg")) {
chdir("/var/www/heatpumpmonitororg");
} elseif(is_dir("$dir/www")) {
chdir("$dir/www");
} else {
die("Error: could not find heatpumpmonitor.org directory");
}
define('EMONCMS_EXEC', 1);
// Require core files
require "core.php";
// Load database settings
require "Lib/load_database.php";
// Include required classes
require ("Modules/system/system_model.php");
require ("Modules/system/system_photos_model.php");
// Parse command line arguments
$system_id = null;
$force_all = false;
$verbose = false;
// Allow this script to allocate more memory and time if needed
ini_set('memory_limit', '512M');
set_time_limit(0);
// Check for command line options
if (php_sapi_name() === 'cli' && isset($argv)) {
for ($i = 1; $i < count($argv); $i++) {
if ($argv[$i] === '--force-all') {
$force_all = true;
} elseif ($argv[$i] === '--verbose') {
$verbose = true;
} elseif (is_numeric($argv[$i])) {
$system_id = (int)$argv[$i];
}
}
}
// Initialize models (mysqli connection is already established in load_database.php)
$system = new System($mysqli);
$system_photos = new SystemPhotos($mysqli, $system);
if ($verbose) {
echo "Starting thumbnail generation script...\n";
if ($force_all) {
echo "Mode: Force regeneration of ALL thumbnails\n";
} else {
echo "Mode: Generate missing/incomplete thumbnails\n";
}
if ($system_id) {
echo "Processing system ID: $system_id\n";
} else {
echo "Processing all systems\n";
}
echo "Timestamp: " . date('Y-m-d H:i:s') . "\n";
echo "----------------------------------------\n";
}
// Generate thumbnails
$results = $system_photos->generateThumbnails($system_id, $force_all);
// Output results
if ($verbose) {
echo "Results:\n";
echo " Total images processed: " . $results['total_processed'] . "\n";
echo " Successful: " . $results['successful'] . "\n";
echo " Failed: " . $results['failed'] . "\n";
if (isset($results['skipped'])) {
echo " Skipped (already complete): " . $results['skipped'] . "\n";
}
if (!empty($results['errors'])) {
echo "\nErrors:\n";
foreach ($results['errors'] as $error) {
echo " - $error\n";
}
}
echo "\nScript completed at: " . date('Y-m-d H:i:s') . "\n";
}
// Exit with appropriate code
if ($results['failed'] > 0) {
exit(2); // Some failures occurred
} elseif ($results['total_processed'] == 0) {
exit(0); // No images to process (normal)
} else {
exit(0); // All successful
}