Beispiel #1
0
 public function testInsertOrUpdateWithPreviousValue()
 {
     $this->helper->insert('car', ['make' => 'volvo', 'model' => 'xc90']);
     $this->helper->insertOrUpdate('car', ['make' => 'volvo', 'model' => 'v70'], ['make' => 'volvo']);
     $cars = $this->helper->select('car');
     $this->assertCount(1, $cars);
     $this->assertEquals('volvo', $cars[0]['make']);
     $this->assertEquals('v70', $cars[0]['model']);
 }
 /**
  * @param Media[] $media
  * @return int number of saved medias
  */
 public function insert(array $media)
 {
     $inserts = 0;
     foreach ($media as $it) {
         try {
             $this->helper->insert('vss_media', ['source' => $it->getSource(), 'original_id' => $it->originalId, 'text' => $it->text, 'images' => json_encode($it->images), 'videos' => json_encode($it->videos), 'lat' => $it->lat, 'long' => $it->long, 'username' => $it->username, 'created_at' => $it->createdAt, 'url' => $it->url, 'active' => (int) $it->active, 'like_count' => $it->like_count, 'comment_count' => $it->comment_count]);
             $maxId = $this->getLastId();
             foreach ($it->tags as $tag) {
                 $this->helper->insert('vss_tag', ['name' => $tag, 'vss_media_id' => $maxId]);
             }
             $inserts++;
         } catch (\Exception $e) {
             error_log($e->getMessage());
         }
     }
     return $inserts;
 }