PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/_build/resolvers/setupoptions.resolver.php

https://github.com/modx-fr/VersionX2
PHP | 107 lines | 83 code | 17 blank | 7 comment | 34 complexity | 227bf5a98b77d7dabb47475969ac1194 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. if (isset($object) && isset($object->xpdo)) {
  3. $modx = $object->xpdo;
  4. }
  5. if (!isset($modx)) {
  6. require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/revolution/config.core.php';
  7. require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
  8. $modx= new modX();
  9. $modx->initialize('web');
  10. $modx->setLogLevel(modX::LOG_LEVEL_INFO);
  11. $modx->setLogTarget('ECHO');
  12. }
  13. switch ($options[xPDOTransport::PACKAGE_ACTION]) {
  14. case xPDOTransport::ACTION_UPGRADE:
  15. case xPDOTransport::ACTION_INSTALL:
  16. @set_time_limit(0);
  17. /* @var VersionX $versionx */
  18. $corePath = $modx->getOption('versionx.core_path',null,$modx->getOption('core_path').'components/versionx/');
  19. $versionx = $modx->getService('versionx','VersionX',$corePath.'/model/');
  20. $versionx->initialize('mgr');
  21. $modx->log(modX::LOG_LEVEL_INFO,'Starting snapshot process for selected objects...');
  22. /* If we wanted resources snapshot, make that */
  23. if (isset($options['vx_snapshot_resources']) && !empty($options['vx_snapshot_resources'])) {
  24. $modx->log(modX::LOG_LEVEL_INFO,'Iterating over Resources and storing snapshots..');
  25. $count = 0;
  26. foreach ($modx->getIterator('modResource') as $object) {
  27. if ($versionx->newResourceVersion($object, 'snapshot')) { $count++; }
  28. else { $modx->log(modX::LOG_LEVEL_WARN,'Error creating snapshot for Resource '.$object->get('id')); }
  29. if (is_int($count / 25)) { $modx->log(modX::LOG_LEVEL_INFO,"Checked {$count} Resources so far."); }
  30. }
  31. $modx->log(modX::LOG_LEVEL_WARN,'Iterated over '.$count.' Resources.');
  32. }
  33. /* If we wanted template snapshot, make that */
  34. if (isset($options['vx_snapshot_templates']) && !empty($options['vx_snapshot_templates'])) {
  35. $modx->log(modX::LOG_LEVEL_INFO,'Iterating over Templates and storing snapshots..');
  36. $count = 0;
  37. foreach ($modx->getIterator('modTemplate') as $object) {
  38. if ($versionx->newTemplateVersion($object, 'snapshot')) { $count++; }
  39. else { $modx->log(modX::LOG_LEVEL_WARN,'Error creating snapshot for Template '.$object->get('id')); }
  40. if (is_int($count / 10)) { $modx->log(modX::LOG_LEVEL_INFO,"Checked {$count} Templates so far."); }
  41. }
  42. $modx->log(modX::LOG_LEVEL_WARN,'Iterated over '.$count.' Templates.');
  43. }
  44. /* If we wanted chunk snapshot, make that */
  45. if (isset($options['vx_snapshot_chunks']) && !empty($options['vx_snapshot_chunks'])) {
  46. $modx->log(modX::LOG_LEVEL_INFO,'Iterating over Chunks and storing snapshots..');
  47. $count = 0;
  48. foreach ($modx->getIterator('modChunk') as $object) {
  49. if ($versionx->newChunkVersion($object, 'snapshot')) { $count++; }
  50. else { $modx->log(modX::LOG_LEVEL_WARN,'Error creating snapshot for Chunk '.$object->get('id')); }
  51. if (is_int($count / 25)) { $modx->log(modX::LOG_LEVEL_INFO,"Checked {$count} Chunks so far."); }
  52. }
  53. $modx->log(modX::LOG_LEVEL_WARN,'Iterated over '.$count.' Chunks.');
  54. }
  55. /* If we wanted snippet snapshot, make that */
  56. if (isset($options['vx_snapshot_snippets']) && !empty($options['vx_snapshot_snippets'])) {
  57. $modx->log(modX::LOG_LEVEL_INFO,'Iterating over Snippets and storing snapshots..');
  58. $count = 0;
  59. foreach ($modx->getIterator('modSnippet') as $object) {
  60. if ($versionx->newSnippetVersion($object, 'snapshot')) { $count++; }
  61. else { $modx->log(modX::LOG_LEVEL_WARN,'Error creating snapshot for Snippet '.$object->get('id')); }
  62. if (is_int($count / 10)) { $modx->log(modX::LOG_LEVEL_INFO,"Checked {$count} Snippets so far."); }
  63. }
  64. $modx->log(modX::LOG_LEVEL_WARN,'Iterated over '.$count.' Snippets.');
  65. }
  66. /* If we wanted plugins snapshot, make that */
  67. if (isset($options['vx_snapshot_plugins']) && !empty($options['vx_snapshot_plugins'])) {
  68. $modx->log(modX::LOG_LEVEL_INFO,'Iterating over Plugins and storing snapshots..');
  69. $count = 0;
  70. foreach ($modx->getIterator('modPlugin') as $object) {
  71. if ($versionx->newPluginVersion($object, 'snapshot')) { $count++; }
  72. else { $modx->log(modX::LOG_LEVEL_WARN,'Error creating snapshot for Plugin '.$object->get('id')); }
  73. if (is_int($count / 10)) { $modx->log(modX::LOG_LEVEL_INFO,"Checked {$count} Plugins so far."); }
  74. }
  75. $modx->log(modX::LOG_LEVEL_WARN,'Iterated over '.$count.' Plugins.');
  76. }
  77. /* If we wanted tv snapshot, make that */
  78. if (isset($options['vx_snapshot_tmplvars']) && !empty($options['vx_snapshot_tmplvars'])) {
  79. $modx->log(modX::LOG_LEVEL_INFO,'Iterating over Template Variables and storing snapshots..');
  80. $count = 0;
  81. foreach ($modx->getIterator('modTemplateVar') as $object) {
  82. if ($versionx->newTemplateVarVersion($object, 'snapshot')) { $count++; }
  83. else { $modx->log(modX::LOG_LEVEL_WARN,'Error creating snapshot for Template Variable '.$object->get('id')); }
  84. if (is_int($count / 10)) { $modx->log(modX::LOG_LEVEL_INFO,"Checked {$count} Template Variables so far."); }
  85. }
  86. $modx->log(modX::LOG_LEVEL_WARN,'Iterated over '.$count.' Template Variables.');
  87. }
  88. break;
  89. }
  90. return true;