src/libraries/controllers/ApiPhotoController.php
/**
    * Update the data associated with the photo in the remote data store.
    * Parameters to be updated are in _POST
    * This method also manages updating tag counts
    *
    * @param string $id ID of the photo to be updated.
    * @return string Standard JSON envelope
    */
Update the data associated with the photo in the remote data store.
Parameters to be updated are in _POST
This method also manages updating tag counts

@param string $id ID of the photo to be updated.
@return string Standard JSON envelope
Update the data associated with the photo in the remote data store . Parameters to be updated are in _POST This method also manages updating tag counts @param string $id ID of the photo to be updated . @return string Standard JSON envelope
public function update($id)
  {
    $this->logger->info(sprintf('Calling ApiPhotoController::update with %s', $id));
    getAuthentication()->requireAuthentication();
    getAuthentication()->requireCrumb();
    $params = $_POST;
    $photoBefore = $this->api->invoke("/{$this->apiVersion}/photo/{$id}/view.json", EpiRoute::httpGet);
    $photoBefore = $photoBefore['result'];
    if(isset($params['tags']) || isset($params['tagsAdd']) || isset($params['tagsRemove']))
    {
      if($photoBefore)
      {
        $existingTags = $photoBefore['tags'];
        $updatedTags = array();
        if(isset($params['tags']))
        {
          $updatedTags = array_merge($updatedTags, (array)explode(',', $params['tags']));
        }
        else
        {
          $updatedTags = $existingTags;
          if(isset($params['tagsAdd']))
          {
            $updatedTags = array_merge($updatedTags, (array)explode(',', $params['tagsAdd']));
            unset($params['tagsAdd']);
          }
          if(isset($params['tagsRemove']))
          {
            $updatedTags = array_diff($updatedTags, (array)explode(',', $params['tagsRemove']));
            unset($params['tagsRemove']);
          }
          $params['tags'] = implode(',', $updatedTags);
        }
        $permission = $photoBefore['permission'];
        if(isset($params['permission']))
          $permission = $params['permission'];
        $this->tag->updateTagCounts($existingTags, $updatedTags, $permission, $photoBefore['permission']);
      }
    }
    if(isset($params['albumsAdd']))
    {
      $params['albums'] = implode(',', array_merge($photoBefore['albums'], $params['albumsAdd']));
    }
    if(isset($params['albums']))
    {
      $this->updateAlbums($params['albums'], $id, $photoBefore);
      if(is_array($params['albums']))
        $params['albums'] = implode(',', $params['albums']);
    }
    if(isset($params['groups']) && is_array($params['groups']))
      $params['groups'] = implode(',', $params['groups']);
    if(isset($params['crumb']))
      unset($params['crumb']);
    $photoUpdatedId = $this->photo->update($id, $params);
    if($photoUpdatedId)
    {
      $apiResp = $this->api->invoke("/{$this->apiVersion}/photo/{$id}/view.json", EpiRoute::httpGet, array('_GET' => array('returnSizes' => '100x100xCR', 'generate' => 'true')));
      $photo = $apiResp['result'];
      $post = array('type' => 'photo-update', 'data' => $photo);
      if(isset($params['permission']))
        $post['permission'] = $params['permission'];
      $this->api->invoke("/{$this->apiVersion}/activity/create.json", EpiRoute::httpPost, array('_POST' => $post));
      return $this->success("photo {$id} updated", $photo);
    }
    return $this->error("photo {$id} could not be updated", false);
  }
public function update ( $ id ) { $ this -> logger -> info ( sprintf ( 'Calling ApiPhotoController::update with %s' , $ id ) ) ; getAuthentication ( ) -> requireAuthentication ( ) ; getAuthentication ( ) -> requireCrumb ( ) ; $ params = $ _POST ; $ photoBefore = $ this -> api -> invoke ( " / { $ this -> apiVersion } /photo/ { $ id } /view.json " , EpiRoute :: httpGet ) ; $ photoBefore = $ photoBefore [ 'result' ] ; if ( isset ( $ params [ 'tags' ] ) || isset ( $ params [ 'tagsAdd' ] ) || isset ( $ params [ 'tagsRemove' ] ) ) { if ( $ photoBefore ) { $ existingTags = $ photoBefore [ 'tags' ] ; $ updatedTags = array ( ) ; if ( isset ( $ params [ 'tags' ] ) ) { $ updatedTags = array_merge ( $ updatedTags , ( array ) explode ( ',' , $ params [ 'tags' ] ) ) ; } else { $ updatedTags = $ existingTags ; if ( isset ( $ params [ 'tagsAdd' ] ) ) { $ updatedTags = array_merge ( $ updatedTags , ( array ) explode ( ',' , $ params [ 'tagsAdd' ] ) ) ; unset ( $ params [ 'tagsAdd' ] ) ; } if ( isset ( $ params [ 'tagsRemove' ] ) ) { $ updatedTags = array_diff ( $ updatedTags , ( array ) explode ( ',' , $ params [ 'tagsRemove' ] ) ) ; unset ( $ params [ 'tagsRemove' ] ) ; } $ params [ 'tags' ] = implode ( ',' , $ updatedTags ) ; } $ permission = $ photoBefore [ 'permission' ] ; if ( isset ( $ params [ 'permission' ] ) ) $ permission = $ params [ 'permission' ] ; $ this -> tag -> updateTagCounts ( $ existingTags , $ updatedTags , $ permission , $ photoBefore [ 'permission' ] ) ; } } if ( isset ( $ params [ 'albumsAdd' ] ) ) { $ params [ 'albums' ] = implode ( ',' , array_merge ( $ photoBefore [ 'albums' ] , $ params [ 'albumsAdd' ] ) ) ; } if ( isset ( $ params [ 'albums' ] ) ) { $ this -> updateAlbums ( $ params [ 'albums' ] , $ id , $ photoBefore ) ; if ( is_array ( $ params [ 'albums' ] ) ) $ params [ 'albums' ] = implode ( ',' , $ params [ 'albums' ] ) ; } if ( isset ( $ params [ 'groups' ] ) && is_array ( $ params [ 'groups' ] ) ) $ params [ 'groups' ] = implode ( ',' , $ params [ 'groups' ] ) ; if ( isset ( $ params [ 'crumb' ] ) ) unset ( $ params [ 'crumb' ] ) ; $ photoUpdatedId = $ this -> photo -> update ( $ id , $ params ) ; if ( $ photoUpdatedId ) { $ apiResp = $ this -> api -> invoke ( " / { $ this -> apiVersion } /photo/ { $ id } /view.json " , EpiRoute :: httpGet , array ( '_GET' => array ( 'returnSizes' => '100x100xCR' , 'generate' => 'true' ) ) ) ; $ photo = $ apiResp [ 'result' ] ; $ post = array ( 'type' => 'photo-update' , 'data' => $ photo ) ; if ( isset ( $ params [ 'permission' ] ) ) $ post [ 'permission' ] = $ params [ 'permission' ] ; $ this -> api -> invoke ( " / { $ this -> apiVersion } /activity/create.json " , EpiRoute :: httpPost , array ( '_POST' => $ post ) ) ; return $ this -> success ( " photo  { $ id }  updated " , $ photo ) ; } return $ this -> error ( " photo  { $ id }  could not be updated " , false ) ; }
Update the data associated with the photo in the remote data store.
Update the data associated with the photo in the remote data store .
// diff/manage tag counts - not critical