settings2csv.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script generates a CSV file of all settings in the order they appear
  5. * in the platform settings section, in the given language.
  6. * This is meant to speed up the redaction of the admin guide.
  7. * Note: to obtain the default values for all settings, you need to run
  8. * this script on a freshly installed Chamilo setup with all options set
  9. * by default in the installation process.
  10. * @package chamilo.tests.scripts
  11. */
  12. /**
  13. * Init
  14. */
  15. // comment exit statement before executing
  16. exit;
  17. /* Usage doc */
  18. if ($argc <= 1) {
  19. echo 'Usage: php settings2csv.php [language]'.PHP_EOL;
  20. echo ' Where the language name is supported by Chamilo. e.g. french, spanish, ...'.PHP_EOL;
  21. echo ' (defaults to "english").'.PHP_EOL;
  22. echo ' The resulting filepath will appear on the output line'.PHP_EOL.PHP_EOL;
  23. }
  24. $language = 'english';
  25. if (!empty($argv[1])) {
  26. $language = $argv[1];
  27. }
  28. $_GET['language'] = $language;
  29. @require __DIR__ . '/../../main/inc/global.inc.php';
  30. // Categories, in order of appearance in the Chamilo settings page
  31. // Check the end of main/admin/settings.php for the initial list
  32. $categories = [
  33. 'Platform',
  34. 'Course',
  35. 'Session',
  36. 'Languages',
  37. 'User',
  38. 'Tools',
  39. 'Editor',
  40. 'Security',
  41. 'Tuning',
  42. 'Gradebook',
  43. 'Timezones',
  44. 'Tracking',
  45. 'Search',
  46. 'Stylesheets',
  47. 'Templates',
  48. 'Plugins',
  49. 'LDAP',
  50. 'CAS',
  51. 'Shibboleth',
  52. 'Facebook',
  53. 'Crons',
  54. 'WebServices',
  55. ];
  56. $fileName = 'settings'; // will be appended a ".csv" extension
  57. $fileContent = [];
  58. $fileContent[] = [
  59. 'Variable',
  60. 'Subkey',
  61. 'Comment',
  62. 'Current value'
  63. ];
  64. foreach ($categories as $category) {
  65. $fileContent[] = [
  66. '***** '.get_lang('Category', null, $language).': '.$category.' ****',
  67. '',
  68. '',
  69. ''
  70. ];
  71. $settings = api_get_settings($category, 'group');
  72. foreach ($settings as $setting) {
  73. $fileContent[] = [
  74. get_lang($setting['title'], null, $language),
  75. $setting['subkey'],
  76. get_lang($setting['comment'], null, $language),
  77. $setting['selected_value']
  78. ];
  79. }
  80. }
  81. $filePath = Export::arrayToCsv($fileContent, $fileName, true);
  82. echo "File generated and stored in $filePath".PHP_EOL;