1. <?php
  2. /**
  3. * CLI tool to manage maintenance file paths.
  4. */
  5. // Function to display usage instructions.
  6. function displayUsage() {
  7. echo "Usage: php manage_maintenance_paths.php <option>\n";
  8. echo "Options:\n";
  9. echo " -set <path> <task> - Sets the path for a specific task.\n";
  10. echo " -list - Lists all configured paths.\n";
  11. echo " -remove <task> - Removes the path for a specific task.\n";
  12. }
  13. // Main function to handle CLI arguments.
  14. function main() {
  15. $config_file = 'maintenance_paths.php'; // File to store configurations
  16. if (!file_exists($config_file)) {
  17. file_put_contents($config_file, serialize(array())); // Create if it doesn't exist
  18. }
  19. $arguments = getopt('set:list:remove:', ['path:', 'task:']);
  20. if (empty($arguments)) {
  21. displayUsage();
  22. return;
  23. }
  24. $paths = unserialize(file_get_contents($config_file));
  25. switch ($arguments['set']) {
  26. case 'set':
  27. if (isset($arguments['path']) && isset($arguments['task'])) {
  28. $path = $arguments['path'];
  29. $task = $arguments['task'];
  30. $paths[$task] = $path;
  31. file_put_contents($config_file, serialize($paths));
  32. echo "Path for task '$task' set to '$path'.\n";
  33. } else {
  34. displayUsage();
  35. }
  36. break;
  37. case 'list':
  38. if (!empty($paths)) {
  39. echo "Maintenance Paths:\n";
  40. foreach ($paths as $task => $path) {
  41. echo " $task: $path\n";
  42. }
  43. } else {
  44. echo "No paths configured.\n";
  45. }
  46. break;
  47. case 'remove':
  48. if (isset($arguments['task'])) {
  49. $task = $arguments['task'];
  50. if (isset($paths[$task])) {
  51. unset($paths[$task]);
  52. file_put_contents($config_file, serialize($paths));
  53. echo "Path for task '$task' removed.\n";
  54. } else {
  55. echo "Task '$task' not found.\n";
  56. }
  57. } else {
  58. displayUsage();
  59. }
  60. break;
  61. default:
  62. displayUsage();
  63. }
  64. }
  65. // Run the main function.
  66. if (PHP_SAPI == 'cli') {
  67. main();
  68. }
  69. ?>

Add your comment