/PHP/Classes/Plugins/CMS/Routines/ImageContent/FullPopulationImageContentStorageRoutine.php

https://github.com/GunioRobot/eglooframework · PHP · 98 lines · 38 code · 17 blank · 43 comment · 10 complexity · d40e7379c4052218303cd6407569010b MD5 · raw file

  1. <?php
  2. /**
  3. * FullPopulationImageContentStorageRoutine Class File
  4. *
  5. * Contains the class definition for the FullPopulationImageContentStorageRoutine
  6. *
  7. * Copyright 2011 eGloo LLC
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. * @author George Cooper
  22. * @copyright 2011 eGloo LLC
  23. * @license http://www.apache.org/licenses/LICENSE-2.0
  24. * @package $package
  25. * @subpackage $subpackage
  26. * @version 1.0
  27. */
  28. /**
  29. * FullPopulationImageContentStorageRoutine
  30. *
  31. * $short_description
  32. *
  33. * $long_description
  34. *
  35. * @package $package
  36. * @subpackage $subpackage
  37. */
  38. class FullPopulationImageContentStorageRoutine extends StorageRoutine {
  39. public function storeContent( $imageDTO, $storage_method = 'egDataStore', $manipulation_routine = null ) {
  40. $contentDAOFactory = ContentDAOFactory::getInstance();
  41. // TODO Apply any image modifications/adjustments needed
  42. if ( $manipulation_routine !== null ) {
  43. if ( is_object( $manipulation_routine ) ) {
  44. $imageDTO = $manipulation_routine->manipulateContent( $imageDTO );
  45. } else if ( is_string( $manipulation_routine ) ) {
  46. $manipulationRoutineObj = new $manipulation_routine();
  47. $imageDTO = $manipulationRoutineObj->manipulateContent( $imageDTO );
  48. }
  49. }
  50. $storedImageDTO = null;
  51. // Store this somewhere
  52. if ( $storage_method === 'egDataStore' ) {
  53. // Store image in data store on FS
  54. $storedImageDTO = $this->storeContentIneGlooDataStore( $imageDTO );
  55. // Update image location entry in DB
  56. $imageContentDBDAO = $contentDAOFactory->getImageContentDAO( 'egPrimary' );
  57. $imageContentDBDAO->storeUploadedImage( $storedImageDTO );
  58. }
  59. // TODO Synchronize content across web servers
  60. // Update CDN entry if using a CDN
  61. $distribution_image_url = null;
  62. if ( eGlooConfiguration::getDeployment() == eGlooConfiguration::PRODUCTION && eGlooConfiguration::getUseCDN() ) {
  63. $imageContentCDNDAO = $contentDAOFactory->getImageContentDAO( 'egCDNPrimary' );
  64. $distribution_image_url = $imageContentCDNDAO->storeImage( $storedImageDTO );
  65. }
  66. if ( $distribution_image_url !== null ) {
  67. // Update image distribution url entry in DB
  68. $imageContentDBDAO = $contentDAOFactory->getImageContentDAO( 'egPrimary' );
  69. $imageContentDBDAO->setImageDistributionURL( $storedImageDTO, $distribution_image_url );
  70. }
  71. }
  72. private function storeContentIneGlooDataStore( $imageDTO ) {
  73. $storedImageDTO = null;
  74. $contentDAOFactory = ContentDAOFactory::getInstance();
  75. $imageContentDAO = $contentDAOFactory->getImageContentDAO();
  76. if ( !( $storedImageDTO = $imageContentDAO->storeUploadedImage( $imageDTO ) ) ) {
  77. throw new ErrorException( 'No valid storage path returned' );
  78. }
  79. return $storedImageDTO;
  80. }
  81. }