Beispiel #1
0
 /**
  * @param string $name
  * @param $files
  * @param array $scrapeList
  * @throws \yii\db\Exception
  */
 protected function updateScrapes($name, $files, array $scrapeList)
 {
     $insert = [];
     $delete = [];
     $bad = [];
     foreach ($scrapeList as $scrapeId => $item) {
         if (empty($files[$item['hash']])) {
             $bad[] = $scrapeId;
         } else {
             $file = $files[$item['hash']];
             $fields = [$item['torrentId'], $name, Scrape::STATUS_GOOD, empty($file['complete']) ? 0 : $file['complete'], empty($file['incomplete']) ? 0 : $file['incomplete'], empty($file['downloaded']) ? 0 : $file['downloaded']];
             $delete[] = $scrapeId;
             $insert[] = $fields;
         }
     }
     if (!empty($bad)) {
         Scrape::updateAll(['status' => Scrape::STATUS_BAD], 'id in ("' . join('","', $bad) . '")');
     }
     if (!empty($delete) && !empty($insert)) {
         Scrape::deleteAll('id in ("' . join('","', $delete) . '")');
         \Yii::$app->db->createCommand()->batchInsert('scrapes', ['torrent_id', 'name', 'status', 'complete', 'incomplete', 'downloaded'], $insert)->execute();
     }
 }
Beispiel #2
0
 /**
  * relation with scrapes
  * @return \yii\db\ActiveQuery
  */
 public function getScrapes()
 {
     return $this->hasMany(Scrape::className(), ['torrent_id' => 'id']);
 }