Changeset 79 for branches/1.1dev/bin/module_maker/module.cli.php
- Timestamp:
- Apr 5, 2006 7:16:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1dev/bin/module_maker/module.cli.php
r78 r79 1 #!/usr/local/bin/php -q1 #!/usr/local/bin/php 2 2 <?php 3 3 /** … … 7 7 8 8 9 $CFG->enable_session = false; 10 $CFG->log_screen_priority = LOG_DEBUG; 11 error_reporting(E_ALL); 12 require_once dirname(__FILE__) . '/../../config/boot.inc.php'; 9 // Get module maker configuration. 10 require_once dirname(__FILE__) . '/_config.inc.php'; 13 11 14 12 … … 18 16 19 17 // Test for a single argument. 20 if ($_SERVER['argc'] == 4 && $_SERVER['argv'][3] == 'clean') {21 $module_name_singular = $_SERVER['argv'][ 1];22 $module_name_plural = $_SERVER['argv'][ 2];23 } else if ($_SERVER['argc'] == 3) {18 if ($_SERVER['argc'] == 5 && $_SERVER['argv'][4] == 'clean') { 19 $module_name_singular = $_SERVER['argv'][2]; 20 $module_name_plural = $_SERVER['argv'][3]; 21 } else if ($_SERVER['argc'] == 4) { 24 22 // Normal operation. 25 $module_name_singular = $_SERVER['argv'][ 1];26 $module_name_plural = $_SERVER['argv'][ 2];27 } else if ($_SERVER['argc'] == 2 && $_SERVER['argv'][1] == '_default_') {23 $module_name_singular = $_SERVER['argv'][2]; 24 $module_name_plural = $_SERVER['argv'][3]; 25 } else if ($_SERVER['argc'] == 3 && $_SERVER['argv'][2] == '_default_') { 28 26 // Hacked mode: use these module names: 29 27 $module_name_singular = 'event'; … … 33 31 die(basename($_SERVER['argv'][0]) . " Error: invalid arguments. Try like this: 34 32 35 " . basename($_SERVER['argv'][0]) . " <namesingular> <nameplural> 33 " . basename($_SERVER['argv'][0]) . " <sitedirectory> <namesingular> <nameplural> 34 35 E.g.: " . basename($_SERVER['argv'][0]) . " ~/Sites/www.asdf.com category categories 36 36 37 37 There is also a secret _default_ option that uses options hard-coded into the script. Hack the script for more info. … … 48 48 49 49 // Where deleted files go: 50 $user_trash_folder = "/Users/" . get_current_user() . "/.Trash";50 $user_trash_folder = $_SERVER['HOME'] . '/.Trash'; 51 51 52 52 // Directories … … 77 77 78 78 79 if ($_SERVER['argc'] == 4 && $_SERVER['argv'][3] == 'clean') { 80 cleanFiles(); 79 // Only after we've defined essential files can we clean. 80 if ($_SERVER['argc'] == 5 && $_SERVER['argv'][4] == 'clean') { 81 echo "Beginning file cleanup\n"; 82 trashFile("$admin_dir/$admin_script"); 83 trashFile("$admin_tpl_dir/$admin_list_template"); 84 trashFile("$admin_tpl_dir/$admin_form_template"); 85 trashFile("$public_dir/$public_script"); 86 trashFile("$public_tpl_dir/$public_list_template"); 87 trashFile("$public_tpl_dir/$public_detail_template"); 88 echo "End file cleanup\n"; 81 89 die; 82 90 } 91 92 // Go! 93 echo 'Running Module Maker. Using database: ' . $CFG->database . "\n"; 94 83 95 84 96 /****************************************************************************** … … 395 407 *****************************************************************************/ 396 408 397 /** 398 * Removes existing modules files. Danger! 399 */ 400 function cleanFiles() 409 function trashFile($file_path_name) 401 410 { 402 411 global $user_trash_folder; 403 global $admin_dir; 404 global $admin_script; 405 global $admin_tpl_dir; 406 global $admin_list_template; 407 global $admin_form_template; 408 global $public_dir; 409 global $public_script; 410 global $public_tpl_dir; 411 global $public_detail_template; 412 global $public_list_template; 413 414 echo "Beginning file cleanup\n"; 415 416 if (!dir($user_trash_folder)) { 417 mkdir($user_trash_folder); 418 chmod($user_trash_folder, 0777); 419 echo "Attempting to create user trash folder: $user_trash_folder/\n"; 412 static $file_prefix; 413 414 if (!isset($file_prefix)) { 415 $file_prefix = time(); 416 } else { 417 $file_prefix++; 420 418 } 421 if (!dir("$user_trash_folder/") || !is_writable("$user_trash_folder/")) { 419 420 // Make user trash folder. 421 if (!is_dir($user_trash_folder)) { 422 echo "Attempting to create user trash folder: $user_trash_folder/\n"; 423 mkdir($user_trash_folder); 424 chmod($user_trash_folder, 0777); 425 } 426 if (!is_dir("$user_trash_folder") || !is_writable("$user_trash_folder")) { 422 427 die("User trash directory not available: $user_trash_folder/\n"); 423 428 } 424 429 425 if (file_exists("$admin_dir/$admin_script")) { 426 rename("$admin_dir/$admin_script", "$user_trash_folder/$admin_script" . '_' . md5(microtime())); 427 printf("Moved to trash: %s\n", "$admin_dir/$admin_script"); 430 // Move file to trash. 431 if (file_exists($file_path_name)) { 432 rename($file_path_name, sprintf('%s/%s_%s', $user_trash_folder, $file_prefix, basename($file_path_name))); 433 printf("Moved: %s -> %s\n", $file_path_name, sprintf('%s/%s_%s', $user_trash_folder, $file_prefix, basename($file_path_name))); 428 434 } else { 429 printf("File not found: %s\n", "$admin_dir/$admin_script");435 printf("File not found: %s\n", $file_path_name); 430 436 } 431 432 if (file_exists("$admin_tpl_dir/$admin_list_template")) {433 rename("$admin_tpl_dir/$admin_list_template", "$user_trash_folder/$admin_list_template" . '_' . md5(microtime()));434 printf("Moved to trash: %s\n", "$admin_tpl_dir/$admin_list_template");435 } else {436 printf("File not found: %s\n", "$admin_tpl_dir/$admin_list_template");437 }438 439 if (file_exists("$admin_tpl_dir/$admin_form_template")) {440 rename("$admin_tpl_dir/$admin_form_template", "$user_trash_folder/$admin_form_template" . '_' . md5(microtime()));441 printf("Moved to trash: %s\n", "$admin_tpl_dir/$admin_form_template");442 } else {443 printf("File not found: %s\n", "$admin_tpl_dir/$admin_form_template");444 }445 446 if (file_exists("$public_dir/$public_script")) {447 rename("$public_dir/$public_script", "$user_trash_folder/$public_script" . '_' . md5(microtime()));448 printf("Moved to trash: %s\n", "$public_dir/$public_script");449 } else {450 printf("File not found: %s\n", "$public_dir/$public_script");451 }452 453 if (file_exists("$public_tpl_dir/$public_list_template")) {454 rename("$public_tpl_dir/$public_list_template", "$user_trash_folder/$public_list_template" . '_' . md5(microtime()));455 printf("Moved to trash: %s\n", "$public_tpl_dir/$public_list_template");456 } else {457 printf("File not found: %s\n", "$public_tpl_dir/$public_list_template");458 }459 460 if (file_exists("$public_tpl_dir/$public_detail_template")) {461 rename("$public_tpl_dir/$public_detail_template", "$user_trash_folder/$public_detail_template" . '_' . md5(microtime()));462 printf("Moved to trash: %s\n", "$public_tpl_dir/$public_detail_template");463 } else {464 printf("File not found: %s\n", "$public_tpl_dir/$public_detail_template");465 }466 467 echo "End file cleanup\n";468 437 } 469 438
Note: See TracChangeset
for help on using the changeset viewer.