4 * Updates all files within our jurisdiction.
5 * @note This wants to be in a post-commit hook!
10 $xc = XHTMLCompiler
::getInstance();
12 // if in command line mode, allow more options
14 if ($cli = (empty($_SERVER) ||
php_sapi_name() === 'cli')) {
16 $type = isset($argv[1]) ?
$argv[1] : 'normal'; // see below
18 header('Content-type: text/plain');
21 // display a help file
22 if ($type == 'help') {
24 'hc-update.php [type] -- Updates compiled HTML files.
26 . normal : update existing files, remove orphans (default)
27 . all : normal + create files without cached output
28 . force : regenerate all files
29 . clean : remove all cache and dependency files';
34 if ($type == 'clean') {
35 $files = scan_dirs_for_pages('.html', $xc->getConf('allowed_dirs'));
36 foreach ($files as $file) {
37 if (is_created_by_us($file)) {
41 $files = scan_dirs_for_pages('.xc-deps', $xc->getConf('allowed_dirs'));
42 foreach ($files as $file) {
45 exit('Removed all cache and dependency files.');
49 list($files, $src_files) = scan_dirs_for_pages(
50 array('.html', '.xhtml'), $xc->getConf('allowed_dirs')
58 foreach ($files as $file) {
59 $page = new XHTMLCompiler_Page($file, true);
60 // we're only updating files, not creating new ones
61 if ($page->isSourceExistent()) {
63 // don't do it for force, since it's handled below
65 $page->isCacheExistent() &&
69 $updated[] = $page->getCachePath();
71 } elseif (is_created_by_us($page->getCachePath())) {
72 unlink($page); // orphan
73 $orphans[] = $page->getCachePath();
77 foreach ($src_files as $file) {
78 $page = new XHTMLCompiler_Page($file);
79 if ($type == 'all' && !$page->isCacheExistent()) {
80 // generate a new page
82 $created[] = $page->getCachePath();
83 } elseif ($type == 'force') {
85 $updated[] = $page->getCachePath();
90 if (empty($updated)) $updated[] = '(none)';
91 echo wordwrap('Updated pages: ' . implode(', ', $updated)) . PHP_EOL
;
93 if (empty($orphans)) $orphans[] = '(none)';
94 echo wordwrap('Removed orphans: ' . implode(', ', $orphans)) . PHP_EOL
;
96 if ($cli && ($type != 'force')) {
97 if (empty($created)) $created[] = '(none)';
98 echo wordwrap('Created pages: ' . implode(', ', $created)) . PHP_EOL
;