/php/component/internal_syncer.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-box-dev/ · PHP · 72 lines · 65 code · 7 blank · 0 comment · 4 complexity · 9d758b08c8e504f342cb03277219d2c1 MD5 · raw file

  1. <?php
  2. namespace common\extensions\external_repository_manager\implementation\box;
  3. use common\libraries\Utilities;
  4. use common\libraries\Redirect;
  5. use common\libraries\PlatformSetting;
  6. use common\libraries\StringUtilities;
  7. use common\libraries\Application;
  8. use common\libraries\Translation;
  9. use common\extensions\external_repository_manager\ExternalRepositoryComponent;
  10. use common\extensions\external_repository_manager\ExternalRepositoryManager;
  11. use repository\RepositoryManager;
  12. use repository\ExternalRepositorySync;
  13. class BoxExternalRepositoryManagerInternalSyncerComponent extends BoxExternalRepositoryManager
  14. {
  15. function run()
  16. {
  17. $syncer = ExternalRepositoryComponent :: factory(ExternalRepositoryComponent :: INTERNAL_SYNCER_COMPONENT, $this);
  18. $syncer->run();
  19. }
  20. function synchronize_internal_repository_object(ExternalRepositoryObject $external_object)
  21. {
  22. $synchronization_data = $external_object->get_synchronization_data();
  23. $content_object = $synchronization_data->get_content_object();
  24. $content_object->set_title($external_object->get_title());
  25. if (PlatformSetting :: get('description_required', 'repository') && StringUtilities :: is_null_or_empty($external_object->get_description()))
  26. {
  27. $content_object->set_description('-');
  28. }
  29. else
  30. {
  31. $content_object->set_description($external_object->get_description());
  32. }
  33. if ($content_object->update())
  34. {
  35. $synchronization_data->set_content_object_timestamp($content_object->get_modification_date());
  36. $synchronization_data->set_external_object_timestamp($external_object->get_modified());
  37. if ($synchronization_data->update())
  38. {
  39. $parameters = $this->get_parameters();
  40. $parameters[Application :: PARAM_ACTION] = RepositoryManager :: ACTION_VIEW_CONTENT_OBJECTS;
  41. $parameters[RepositoryManager :: PARAM_CONTENT_OBJECT_ID] = $content_object->get_id();
  42. $this->redirect(Translation :: get('ObjectUpdated', array(
  43. 'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), false, $parameters, array(
  44. ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY,
  45. ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION));
  46. }
  47. else
  48. {
  49. $parameters = $this->get_parameters();
  50. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
  51. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
  52. $this->redirect(Translation :: get('ObjectFailedUpdated', array(
  53. 'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), true, $parameters);
  54. }
  55. }
  56. else
  57. {
  58. $parameters = $this->get_parameters();
  59. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
  60. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
  61. $this->redirect(Translation :: get('ObjectUpdated', array('OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), true, $parameters);
  62. }
  63. }
  64. }
  65. ?>