src/libraries/adapters/DatabaseMySql.php
/**
    * Update the information for an existing photo.
    * This method overwrites existing values present in $params.
    *
    * @param string $id ID of the photo to update.
    * @param array $params Attributes to update.
    * @return boolean
    */
Update the information for an existing photo.
This method overwrites existing values present in $params.

@param string $id ID of the photo to update.
@param array $params Attributes to update.
@return boolean
Update the information for an existing photo . This method overwrites existing values present in $params . @param string $id ID of the photo to update . @param array $params Attributes to update . @return boolean
public function postPhoto($id, $params)
  {
    if(empty($id))
      return false;
    elseif(empty($params))
      return true;
    $tags = false;
    if(isset($params['tags']))
      $tags = !empty($params['tags']) ? (array)explode(',', $params['tags']) : null;
    foreach($params as $key => $val)
    {
      if(preg_match('/^path\d+x\d+/', $key))
      {
        $versions[$key] = $val;
        unset($params[$key]);
      }
    }
    if(!empty($params))
    {
      if(isset($params['groups']))
      {
        $this->updateGroupToPhotoMapping($id, $params['groups']);
        $params['groups'] = preg_replace(array('/^,|,$/','/,{2,}/'), array('', ','), $params['groups']);
      }
      if(isset($params['albums']))
      {
        $this->updateAlbumToPhotoMapping($id, $params['albums']);
        $params['albums'] = preg_replace(array('/^,|,$/','/,{2,}/'), array('', ','), $params['albums']);
      }
      $params = $this->preparePhoto($id, $params);
      unset($params['id']);
      $bindings = $params['::bindings'];
      $stmt = $this->sqlUpdateExplode($params, $bindings);
      $res = $this->db->execute("UPDATE `{$this->mySqlTablePrefix}photo` SET {$stmt} WHERE `id`=:id AND owner=:owner", 
        array_merge($bindings, array(':id' => $id, ':owner' => $this->owner)));
    }
    if(!empty($versions))
      $resVersions = $this->postVersions($id, $versions);
    if($tags !== false)
    {
      $this->deleteTagsFromElement($id, 'photo');
      if(!empty($tags))
      {
        foreach($tags as $tag)
          $this->addTagToElement($id, $tag, 'photo');
      }
    }
    return (isset($res) && $res !== false) || (isset($resVersions) && $resVersions);
  }
public function postPhoto ( $ id , $ params ) { if ( empty ( $ id ) ) return false ; elseif ( empty ( $ params ) ) return true ; $ tags = false ; if ( isset ( $ params [ 'tags' ] ) ) $ tags = ! empty ( $ params [ 'tags' ] ) ? ( array ) explode ( ',' , $ params [ 'tags' ] ) : null ; foreach ( $ params as $ key => $ val ) { if ( preg_match ( '/^path\d+x\d+/' , $ key ) ) { $ versions [ $ key ] = $ val ; unset ( $ params [ $ key ] ) ; } } if ( ! empty ( $ params ) ) { if ( isset ( $ params [ 'groups' ] ) ) { $ this -> updateGroupToPhotoMapping ( $ id , $ params [ 'groups' ] ) ; $ params [ 'groups' ] = preg_replace ( array ( '/^,|,$/' , '/,{2,}/' ) , array ( '' , ',' ) , $ params [ 'groups' ] ) ; } if ( isset ( $ params [ 'albums' ] ) ) { $ this -> updateAlbumToPhotoMapping ( $ id , $ params [ 'albums' ] ) ; $ params [ 'albums' ] = preg_replace ( array ( '/^,|,$/' , '/,{2,}/' ) , array ( '' , ',' ) , $ params [ 'albums' ] ) ; } $ params = $ this -> preparePhoto ( $ id , $ params ) ; unset ( $ params [ 'id' ] ) ; $ bindings = $ params [ '::bindings' ] ; $ stmt = $ this -> sqlUpdateExplode ( $ params , $ bindings ) ; $ res = $ this -> db -> execute ( " UPDATE ` { $ this -> mySqlTablePrefix } photo` SET  { $ stmt }  WHERE `id`=:id AND owner=:owner " , array_merge ( $ bindings , array ( ':id' => $ id , ':owner' => $ this -> owner ) ) ) ; } if ( ! empty ( $ versions ) ) $ resVersions = $ this -> postVersions ( $ id , $ versions ) ; if ( $ tags !== false ) { $ this -> deleteTagsFromElement ( $ id , 'photo' ) ; if ( ! empty ( $ tags ) ) { foreach ( $ tags as $ tag ) $ this -> addTagToElement ( $ id , $ tag , 'photo' ) ; } } return ( isset ( $ res ) && $ res !== false ) || ( isset ( $ resVersions ) && $ resVersions ) ; }
Update the information for an existing photo.
Update the information for an existing photo .
// path\d+x\d+ keys go into the photoVersion table // TODO: Generalize this and use for tags too -- @jmathai // TODO: Generalize this and use for tags too -- @jmathai // TODO combine this into a multi row insert in addTagsToElement