/php/component/internal_syncer.class.php

https://bitbucket.org/chamilo/chamilo-ext-repo-photobucket-dev/ · PHP · 82 lines · 73 code · 9 blank · 0 comment · 5 complexity · f987f0a930b663f0bd0918605ccec104 MD5 · raw file

  1. <?php
  2. namespace common\extensions\external_repository_manager\implementation\photobucket;
  3. use common\libraries\Application;
  4. use common\libraries\Utilities;
  5. use common\libraries\Redirect;
  6. use common\libraries\Translation;
  7. use common\libraries\PlatformSetting;
  8. use common\libraries\StringUtilities;
  9. use repository\RepositoryManager;
  10. use common\extensions\external_repository_manager\ExternalRepositoryObject;
  11. use common\extensions\external_repository_manager\ExternalRepositoryComponent;
  12. use common\extensions\external_repository_manager\ExternalRepositoryManager;
  13. class PhotobucketExternalRepositoryManagerInternalSyncerComponent extends PhotobucketExternalRepositoryManager
  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. if (StringUtilities :: is_null_or_empty($external_object->get_title()))
  25. {
  26. $content_object->set_title($external_object->get_id() . '.jpg');
  27. }
  28. else
  29. {
  30. $content_object->set_title($external_object->get_title());
  31. }
  32. if (PlatformSetting :: get('description_required', 'repository') && StringUtilities :: is_null_or_empty($external_object->get_description()))
  33. {
  34. $content_object->set_description('-');
  35. }
  36. else
  37. {
  38. $content_object->set_description($external_object->get_description());
  39. }
  40. if ($content_object->update())
  41. {
  42. $synchronization_data->set_content_object_timestamp($content_object->get_modification_date());
  43. $synchronization_data->set_external_object_timestamp($external_object->get_modified());
  44. if ($synchronization_data->update())
  45. {
  46. $parameters = $this->get_parameters();
  47. $parameters[Application :: PARAM_ACTION] = RepositoryManager :: ACTION_VIEW_CONTENT_OBJECTS;
  48. $parameters[RepositoryManager :: PARAM_CONTENT_OBJECT_ID] = $content_object->get_id();
  49. $this->redirect(Translation :: get('ObjectUpdated', array(
  50. 'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), false, $parameters, array(
  51. ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY,
  52. ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION));
  53. }
  54. else
  55. {
  56. $parameters = $this->get_parameters();
  57. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
  58. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
  59. $this->redirect(Translation :: get('ObjectFailedUpdated', array(
  60. 'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), true, $parameters);
  61. }
  62. }
  63. else
  64. {
  65. $parameters = $this->get_parameters();
  66. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_MANAGER_ACTION] = ExternalRepositoryManager :: ACTION_VIEW_EXTERNAL_REPOSITORY;
  67. $parameters[ExternalRepositoryManager :: PARAM_EXTERNAL_REPOSITORY_ID] = $external_object->get_id();
  68. $this->redirect(Translation :: get('ObjectFailedUpdated', array(
  69. 'OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), true, $parameters);
  70. }
  71. }
  72. }
  73. ?>