update() 공개 메소드

Table expression and columns are not escaped and are not safe for user-input.
public update ( string $tableExpression, array $data, array $identifier, array $types = [] ) : integer
$tableExpression string The expression of the table to update quoted or unquoted.
$data array An associative array containing column-value pairs.
$identifier array The update criteria. An associative array containing column-value pairs.
$types array Types of the merged $data and $identifier arrays in that order.
리턴 integer The number of affected rows.
 /**
  * Saves the pool to the database.
  *
  * @param \MusicBox\Entity\Like $pool
  */
 public function save($pool)
 {
     $poolData = array('address_id' => $pool->getAddress()->getId(), 'access_info' => $pool->getAccessInfo());
     if ($pool->getId()) {
         $this->db->update('pools', $poolData, array('pool_id' => $pool->getId()));
         $newFile = $this->handleFileUpload($item);
         if ($newFile) {
             $poolData['image'] = $pool->getImage();
         }
     } else {
         // The pool is new, note the creation timestamp.
         $poolData['created_at'] = time();
         $this->db->insert('pools', $poolData);
         // Get the id of the newly created pool and set it on the entity.
         $id = $this->db->lastInsertId();
         $pool->setId($id);
         // If a new image was uploaded, update the pool with the new
         // filename.
         $newFile = $this->handleFileUpload($pool);
         if ($newFile) {
             $newData = array('image' => $pool->getImage());
             $this->db->update('pools', $newData, array('pool_id' => $id));
         }
     }
 }
예제 #2
1
 /**
  * Saves the artist to the database.
  *
  * @param \MusicBox\Entity\Artist $artist
  */
 public function save($artist)
 {
     $artistData = array('name' => $artist->getName(), 'short_biography' => $artist->getShortBiography(), 'biography' => $artist->getBiography(), 'soundcloud_url' => $artist->getSoundCloudUrl(), 'image' => $artist->getImage());
     if ($artist->getId()) {
         // If a new image was uploaded, make sure the filename gets set.
         $newFile = $this->handleFileUpload($artist);
         if ($newFile) {
             $artistData['image'] = $artist->getImage();
         }
         $this->db->update('artists', $artistData, array('artist_id' => $artist->getId()));
     } else {
         // The artist is new, note the creation timestamp.
         $artistData['created_at'] = time();
         $this->db->insert('artists', $artistData);
         // Get the id of the newly created artist and set it on the entity.
         $id = $this->db->lastInsertId();
         $artist->setId($id);
         // If a new image was uploaded, update the artist with the new
         // filename.
         $newFile = $this->handleFileUpload($artist);
         if ($newFile) {
             $newData = array('image' => $artist->getImage());
             $this->db->update('artists', $newData, array('artist_id' => $id));
         }
     }
 }
 public function update($id, CacheRecord $cacheRecord)
 {
     $count = $this->db->update($this->entityTable, $cacheRecord->toArray(), array("id" => $id));
     if ($count <= 0) {
         throw new InvalidArgumentException("The update failed.");
     }
 }
예제 #4
0
 public function restorePortfolioTitle()
 {
     $totalPortfolioProcessed = 0;
     $nbPortfolioProcessed = 0;
     if ($this->connection->getSchemaManager()->tablesExist(array('icap__portfolio_widget_title'))) {
         $this->log('Restoring portfolio titles...');
         $rowPortfolioTitles = $this->connection->query('SELECT * FROM icap__portfolio_widget_title');
         $sql = 'SELECT aw.id, aw.user_id FROM icap__portfolio_abstract_widget aw WHERE id = :id';
         $stmt = $this->connection->prepare($sql);
         foreach ($rowPortfolioTitles as $rowPortfolioTitle) {
             $stmt->bindValue('id', $rowPortfolioTitle['id']);
             $stmt->execute();
             foreach ($stmt->fetchAll() as $rowAbstractWidget) {
                 $this->connection->update('icap__portfolio', ['title' => $rowPortfolioTitle['title'], 'slug' => $rowPortfolioTitle['slug']], ['id' => $rowAbstractWidget['user_id']]);
             }
             $this->connection->delete('icap__portfolio_abstract_widget', ['id' => $rowPortfolioTitle['id']]);
             ++$nbPortfolioProcessed;
             if ($nbPortfolioProcessed >= 10) {
                 $totalPortfolioProcessed += $nbPortfolioProcessed;
                 $nbPortfolioProcessed = 0;
                 $this->log('    processing portfolio...');
             }
         }
         $this->log(sprintf('  %d portfolio processed', $totalPortfolioProcessed + $nbPortfolioProcessed));
         $this->connection->delete('icap__portfolio_widget_type', ['name' => 'title']);
         $this->connection->getSchemaManager()->dropTable('icap__portfolio_widget_title');
     }
 }
예제 #5
0
 /**
  * Saves the user to the database.
  *
  * @param \MusicBox\Entity\User $user
  */
 public function save($user)
 {
     $userData = array('username' => $user->getUsername(), 'mail' => $user->getMail(), 'role' => $user->getRole());
     // If the password was changed, re-encrypt it.
     if (strlen($user->getPassword()) != 88) {
         $userData['salt'] = uniqid(mt_rand());
         $userData['password'] = $this->encoder->encodePassword($user->getPassword(), $userData['salt']);
     }
     if ($user->getId()) {
         // If a new image was uploaded, make sure the filename gets set.
         $newFile = $this->handleFileUpload($user);
         if ($newFile) {
             $userData['image'] = $user->getImage();
         }
         $this->db->update('users', $userData, array('user_id' => $user->getId()));
     } else {
         // The user is new, note the creation timestamp.
         $userData['created_at'] = time();
         $this->db->insert('users', $userData);
         // Get the id of the newly created user and set it on the entity.
         $id = $this->db->lastInsertId();
         $user->setId($id);
         // If a new image was uploaded, update the user with the new
         // filename.
         $newFile = $this->handleFileUpload($user);
         if ($newFile) {
             $newData = array('image' => $user->getImage());
             $this->db->update('users', $newData, array('user_id' => $id));
         }
     }
 }
예제 #6
0
 public function editLastLoginIp($admin)
 {
     $data = array();
     $lastLoginIp = $admin->getLastLoginIp();
     $data['lastLoginIp'] = $lastLoginIp;
     $result = $this->db->update('admin', $data, array('id' => $admin->getId()));
     return $result;
 }
 private function updateUsername(ChangedUsername $payload)
 {
     $identifier = ['userIdentifier' => $payload->userIdentifier()->toString()];
     $data = [];
     $data['username'] = $payload->newUsername()->toString();
     $data['at'] = $payload->at()->format('Y-m-d H:i:s');
     $this->connection->update($this->table, $data, $identifier);
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function save(Album $album)
 {
     $data = $album->getArrayCopy();
     if (null === $album->getId()) {
         return $this->db->insert('album', $data);
     } else {
         return $this->db->update('album', ['artist' => $data['artist'], 'title' => $data['title']], ['id' => $data['id']]);
     }
 }
예제 #9
0
 /**
  * @param Album $album
  * @param int $id
  * @return int The number of affected rows
  */
 public function save(Album $album, $id = null)
 {
     $data = $album->getArrayCopy();
     if (null === $id) {
         return $this->db->insert('album', $data);
     } else {
         return $this->db->update('album', $data, ['id' => $id]);
     }
 }
 /**
  * @param PublishedPost $publishedPost
  *
  * @return void
  */
 public function save(PublishedPost $publishedPost)
 {
     $data = ['title' => $publishedPost->title, 'content' => $publishedPost->content, 'category' => $publishedPost->category];
     try {
         $this->connection->insert('published_posts', array_merge($data, ['id' => $publishedPost->id]));
     } catch (\Doctrine\DBAL\DBALException $e) {
         $this->connection->update('published_posts', $data, ['id' => $publishedPost->id]);
     }
 }
 /**
  * Sets an item in the store.
  *
  * @param string $key
  * @param mixed $value
  *
  * @return void
  */
 public function set($key, $value)
 {
     if ($this->exists($key)) {
         $this->db->update('configurations', ['value' => $value], ['code' => $key]);
         return;
     }
     // Insert it
     $this->db->insert('configurations', ['code' => $key, 'value' => $value]);
 }
예제 #12
0
 /**
  * @param string $location
  * @param array $data
  */
 public function cacheSearchResult($location, $data)
 {
     $qb = $this->db->createQueryBuilder()->select('*')->from('search_cache', 's')->where('s.location = :location')->setParameter('location', strtolower($location))->execute();
     if (count($qb->fetchAll()) === 0) {
         $this->db->insert('search_cache', ['location' => strtolower($location), 'cache' => serialize($data), 'time' => date('Y-m-d H:i:s')]);
         return;
     }
     $this->db->update('search_cache', ['cache' => serialize($data), 'time' => date('Y-m-d H:i:s')], ['location' => strtolower($location)]);
 }
예제 #13
0
 /**
  * Executes an SQL UPDATE statement on a table.
  *
  * @param array $data An associative array containing column-value pairs.
  * @param array $identifier The update criteria. An associative array containing column-value pairs.
  * @return integer The number of affected rows.
  */
 public function update(array $data, array $identifier)
 {
     if (array_key_exists($this->createdAtRowName, $data)) {
         unset($data[$this->createdAtRowName]);
     }
     if (!array_key_exists($this->updatedAtRowName, $data)) {
         $data[$this->updatedAtRowName] = $this->now->format($this->dateFormat);
     }
     return $this->conn->update($this->getTableName(), $data, $identifier);
 }
 /**
  * Saves the restaurant to the database.
  *
  * @param Restaurant $restaurant
  *
  * @return Restaurant $restaurant
  */
 public function save($restaurant)
 {
     $restaurantData = array('nom' => $restaurant->getNom(), 'adresse' => $restaurant->getAdresse(), 'cp' => $restaurant->getCp(), 'ville' => $restaurant->getVille(), 'ouverture' => $restaurant->getOuverture(), 'fermeture' => $restaurant->getFermeture(), 'likes' => $restaurant->getLikes());
     if ($restaurant->getId()) {
         $this->db->update('restaurants', $restaurantData, array('id' => $restaurant->getId()));
     } else {
         $this->db->insert('restaurants', $restaurantData);
         $last = $this->db->lastInsertId();
         return $this->find($last);
     }
 }
 /**
  * Saves the produit to the database.
  *
  * @param Produit $produit
  *
  * @return Produit $produit
  */
 public function save($produit)
 {
     $produitData = array('nom' => $produit->getNom(), 'prix' => $produit->getPrix(), 'type' => $produit->getType(), 'image' => $produit->getImage(), 'restaurant' => $produit->getRestaurant());
     if ($produit->getId()) {
         $this->db->update('produits', $produitData, array('id' => $produit->getId()));
     } else {
         $this->db->insert('produits', $produitData);
         $last = $this->db->lastInsertId();
         return $this->find($last);
     }
 }
 /**
  * Saves the menu to the database.
  *
  * @param Menu $menu
  *
  * @return Menu $menu
  */
 public function save($menu)
 {
     $menuData = array('nom' => $menu->getNom(), 'prix' => $menu->getPrix(), 'restaurant_id' => $menu->getRestaurant(), 'primary_id' => $menu->getProduit(), 'boisson' => $menu->getBoisson(), 'dessert' => $menu->getDessert());
     if ($menu->getId()) {
         $this->db->update('menus', $menuData, array('id' => $menu->getId()));
     } else {
         $this->db->insert('menus', $menuData);
         $last = $this->db->lastInsertId();
         return $this->find($last);
     }
 }
예제 #17
0
 public function save(Article $article)
 {
     $articleData = array('title' => $article->getTitle(), 'content' => $article->getContent());
     if ($article->getId()) {
         $this->db->update('article', $articleData, array('id' => $article->getId()));
     } else {
         $this->db->insert('article', $articleData);
         $id = $this->getDb()->lastInsertId();
         $article->setId($id);
     }
 }
 /**
  * Saves the like to the database.
  *
  * @param Like $like
  *
  * @return Like $like
  */
 public function save($like)
 {
     $likeData = array('restaurant_id' => $like->getRestaurant(), 'user_id' => $like->getUser());
     if ($like->getId()) {
         $this->db->update('likes', $likeData, array('id' => $like->getId()));
     } else {
         $this->db->insert('likes', $likeData);
         $last = $this->db->lastInsertId();
         return $this->find($last);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function set($key, $value)
 {
     if (!$this->tableExists()) {
         $this->createTable();
     }
     if ($this->has($key)) {
         $this->conn->update(self::TABLE, array($this->valueColumn => serialize($value)), array($this->keyColumn => $this->generateKey($key)));
         return;
     }
     $this->conn->insert(self::TABLE, array($this->keyColumn => $this->generateKey($key), $this->valueColumn => serialize($value)));
 }
예제 #20
0
 public function setUserId($token, $userId, $updateExpiration = false)
 {
     // try to update
     $data = array('userId' => $userId);
     if ($updateExpiration) {
         $data['expires'] = time() + $this->tokenLifetime;
     }
     $r = $this->connection->update($this->tableName, $data, array('token' => $token));
     if (0 === $r) {
         // update failed - create new record
         $this->connection->insert($this->tableName, array('userId' => $userId, 'token' => $token, 'expires' => time() + $this->tokenLifetime));
     }
 }
 public function save($cardKeyClass)
 {
     $cardKeyClassData = array('title' => $cardKeyClass->getTitle(), 'intro' => $cardKeyClass->getIntro(), 'isVipOrInt' => $cardKeyClass->getIsVipOrInt(), 'number' => $cardKeyClass->getNumber());
     if ($cardKeyClass->getId()) {
         $result = $this->db->update('cardKeyClass', $cardKeyClassData, array('id' => $cardKeyClass->getId()));
     } else {
         $this->db->insert('cardKeyClass', $cardKeyClassData);
         $id = $this->db->lastInsertId();
         $cardKeyClass->setId($id);
         $result = $id;
     }
     return $result;
 }
 public function merge($uri, array $data)
 {
     $existing = $this->prepareRowForWrite($this->fetch($uri));
     $data = $this->prepareRowForWrite($data);
     if (null !== $existing) {
         if ($data === $existing) {
             return;
         }
         $this->connection->update($this->table, ['data' => serialize($data + $existing)], ['uri' => $uri]);
     } else {
         $this->connection->insert($this->table, ['uri' => $uri, 'data' => serialize($data)]);
     }
 }
 /**
  * Saves the user to the database.
  *
  * @param User $user
  *
  * @return User $user
  */
 public function save($user)
 {
     $userData = array('username' => $user->getUsername(), 'password' => $user->getPassword(), 'roles' => $user->getRoles());
     if ($user->getId()) {
         // If a new image was uploaded, make sure the filename gets set.
         $this->db->update('users', $userData, array('id' => $user->getId()));
     } else {
         $userData['password'] = $this->encoder->encodePassword($userData['password'], '');
         $this->db->insert('users', $userData);
         $last = $this->db->lastInsertId();
         return $this->find($last);
     }
 }
 public function save($goodsClass)
 {
     $goodsClassData = array('title' => $goodsClass->getTitle(), 'orderBy' => $goodsClass->getOrderBy());
     if ($goodsClass->getId()) {
         $result = $this->db->update('goodsClass', $goodsClassData, array('id' => $goodsClass->getId()));
     } else {
         $this->db->insert('goodsClass', $goodsClassData);
         $id = $this->db->lastInsertId();
         $goodsClass->setId($id);
         $result = $id;
     }
     return $result;
 }
예제 #25
0
 /**
  * Save the teammate
  * @param object $teammate
  * @return object
  */
 public function save($teammate)
 {
     $teammateData = array('firstname' => $teammate->getFirstname(), 'lastname' => $teammate->getLastname(), 'email' => $teammate->getEmail(), 'phone' => $teammate->getPhone(), 'image' => $teammate->getImage());
     if ($teammate->getId()) {
         $this->db->update('teammate', $teammateData, array('id' => $teammate->getId()));
     } else {
         $this->db->insert('teammate', $teammateData);
         // Get the id of the newly created artist and set it on the entity.
         $id = $this->db->lastInsertId();
         $teammate->setId($id);
     }
     return $teammate;
 }
예제 #26
0
 /**
  * Saves the like to the database.
  *
  * @param \MusicBox\Entity\Like $like
  */
 public function save($like)
 {
     $likeData = array('artist_id' => $like->getArtist()->getId(), 'user_id' => $like->getUser()->getId());
     if ($like->getId()) {
         $this->db->update('likes', $likeData, array('like_id' => $like->getId()));
     } else {
         // The like is new, note the creation timestamp.
         $likeData['created_at'] = time();
         $this->db->insert('likes', $likeData);
         // Get the id of the newly created like and set it on the entity.
         $id = $this->db->lastInsertId();
         $like->setId($id);
     }
 }
 /**
  * Saves the group to the database.
  *
  * @param \MusicBox\Entity\Like $group
  */
 public function save($group)
 {
     $groupData = array('artist_id' => $group->getArtist()->getId(), 'user_id' => $group->getUser()->getId());
     if ($group->getId()) {
         $this->db->update('groups', $groupData, array('group_id' => $group->getId()));
     } else {
         // The group is new, note the creation timestamp.
         $groupData['created_at'] = time();
         $this->db->insert('groups', $groupData);
         // Get the id of the newly created group and set it on the entity.
         $id = $this->db->lastInsertId();
         $group->setId($id);
     }
 }
예제 #28
0
 /**
  * Saves the comment to the database.
  *
  * @param \MusicBox\Entity\Comment $comment
  */
 public function save($comment)
 {
     $commentData = array('artist_id' => $comment->getArtist()->getId(), 'user_id' => $comment->getUser()->getId(), 'comment' => $comment->getComment(), 'published' => $comment->getPublished());
     if ($comment->getId()) {
         $this->db->update('comments', $commentData, array('comment_id' => $comment->getId()));
     } else {
         // The comment is new, note the creation timestamp.
         $commentData['created_at'] = time();
         $this->db->insert('comments', $commentData);
         // Get the id of the newly created comment and set it on the entity.
         $id = $this->db->lastInsertId();
         $comment->setId($id);
     }
 }
예제 #29
0
 public function refreshUser(UserInterface $original)
 {
     if (!$this->supportsClass(get_class($original))) {
         throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($original)));
     }
     $user = $this->findUserByName($original->getUsername());
     if (false === $user) {
         throw new UsernameNotFoundException(sprintf('Username "%s" not found.', $original->getUsername()));
     }
     if ($user->getLastVisit() < time() - self::LASTVISIT_UPDATE_THRESHOLD_SEC) {
         $this->conn->update(CoreTables::USER_TBL, ['lastVisit' => time()], ['id' => $user->getId()]);
     }
     return $user;
 }
 /**
  * Saves the lesson to the database.
  *
  * @param \MusicBox\Entity\Like $lesson
  */
 public function save($lesson)
 {
     $lessonData = array('user_id' => $lesson->getUser()->getId());
     if ($lesson->getId()) {
         $this->db->update('lessons', $lessonData, array('lesson_id' => $lesson->getId()));
     } else {
         // The lesson is new, note the creation timestamp.
         $lessonData['created_at'] = time();
         $this->db->insert('lessons', $lessonData);
         // Get the id of the newly created lesson and set it on the entity.
         $id = $this->db->lastInsertId();
         $lesson->setId($id);
     }
 }