/php/component/internal_syncer.class.php
PHP | 72 lines | 65 code | 7 blank | 0 comment | 4 complexity | 9d758b08c8e504f342cb03277219d2c1 MD5 | raw file
1<?php 2namespace common\extensions\external_repository_manager\implementation\box; 3 4use common\libraries\Utilities; 5use common\libraries\Redirect; 6use common\libraries\PlatformSetting; 7use common\libraries\StringUtilities; 8use common\libraries\Application; 9use common\libraries\Translation; 10 11use common\extensions\external_repository_manager\ExternalRepositoryComponent; 12use common\extensions\external_repository_manager\ExternalRepositoryManager; 13 14use repository\RepositoryManager; 15use repository\ExternalRepositorySync; 16 17class BoxExternalRepositoryManagerInternalSyncerComponent extends BoxExternalRepositoryManager 18{ 19 20 function run() 21 { 22 $syncer = ExternalRepositoryComponent :: factory(ExternalRepositoryComponent :: INTERNAL_SYNCER_COMPONENT, $this); 23 $syncer->run(); 24 } 25 26 function synchronize_internal_repository_object(ExternalRepositoryObject $external_object) 27 { 28 $synchronization_data = $external_object->get_synchronization_data(); 29 $content_object = $synchronization_data->get_content_object(); 30 $content_object->set_title($external_object->get_title()); 31 if (PlatformSetting :: get('description_required', 'repository') && StringUtilities :: is_null_or_empty($external_object->get_description())) 32 { 33 $content_object->set_description('-'); 34 } 35 else 36 { 37 $content_object->set_description($external_object->get_description()); 38 } 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('ObjectUpdated', array('OBJECT' => Translation :: get('ContentObject')), Utilities :: COMMON_LIBRARIES), true, $parameters); 69 } 70 } 71} 72?>