1. <?php
  2. /**
  3. * Simple text block resource synchronization.
  4. *
  5. * This script synchronizes text blocks between a source and destination.
  6. * It uses a simple file-based approach and minimal dependencies.
  7. *
  8. * Usage: sync_text_blocks.php <source_directory> <destination_directory>
  9. */
  10. if (count($argv) !== 3) {
  11. die("Usage: sync_text_blocks.php <source_directory> <destination_directory>\n");
  12. }
  13. $source_dir = $argv[1];
  14. $dest_dir = $argv[2];
  15. // Ensure directories exist
  16. if (!is_dir($source_dir)) {
  17. die("Source directory '$source_dir' does not exist.\n");
  18. }
  19. if (!is_dir($dest_dir)) {
  20. mkdir($dest_dir, 0777, true); // Create destination directory if it doesn't exist
  21. }
  22. $files = scandir($source_dir);
  23. if ($files === false) {
  24. die("Failed to read source directory.\n");
  25. }
  26. foreach ($files as $file) {
  27. if ($file == '.' || $file == '..') {
  28. continue;
  29. }
  30. $source_file = $source_dir . '/' . $file;
  31. $dest_file = $dest_dir . '/' . $file;
  32. if (is_file($source_file)) {
  33. // Check if the file exists in the destination
  34. if (!file_exists($dest_file)) {
  35. copy($source_file, $dest_file); // Copy the file
  36. echo "Copied: $file\n";
  37. } else {
  38. // Compare file contents and update if necessary
  39. if (file_get_contents($source_file) !== file_get_contents($dest_file)) {
  40. copy($source_file, $dest_file); // Overwrite with the latest version
  41. echo "Updated: $file\n";
  42. }
  43. }
  44. }
  45. }
  46. echo "Synchronization complete.\n";
  47. ?>

Add your comment