Example #1
0
 /**
  * Create NZB files from complete releases.
  *
  * @param int|string $groupID (optional)
  *
  * @return int
  * @access public
  */
 public function createNZBs($groupID)
 {
     $startTime = time();
     if ($this->echoCLI) {
         $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Create the NZB, delete collections/binaries/parts."));
     }
     $releases = $this->pdo->queryDirect(sprintf("\n\t\t\t\tSELECT SQL_NO_CACHE CONCAT(COALESCE(cp.title,'') , CASE WHEN cp.title IS NULL THEN '' ELSE ' > ' END , c.title) AS title,\n\t\t\t\t\tr.name, r.id, r.guid\n\t\t\t\tFROM releases r\n\t\t\t\tINNER JOIN category c ON r.categoryid = c.id\n\t\t\t\tINNER JOIN category cp ON cp.id = c.parentid\n\t\t\t\tWHERE %s nzbstatus = 0", !empty($groupID) ? ' r.group_id = ' . $groupID . ' AND ' : ' '));
     $nzbCount = 0;
     if ($releases && $releases->rowCount()) {
         $total = $releases->rowCount();
         // Init vars for writing the NZB's.
         $this->nzb->initiateForWrite($groupID);
         foreach ($releases as $release) {
             if ($this->nzb->writeNZBforReleaseId($release['id'], $release['guid'], $release['name'], $release['title']) === true) {
                 $nzbCount++;
                 if ($this->echoCLI) {
                     echo $this->pdo->log->primaryOver("Creating NZBs and deleting Collections:\t" . $nzbCount . '/' . $total . "\r");
                 }
             }
         }
     }
     $totalTime = time() - $startTime;
     if ($this->echoCLI) {
         $this->pdo->log->doEcho($this->pdo->log->primary(number_format($nzbCount) . ' NZBs created/Collections deleted in ' . $totalTime . ' seconds.' . PHP_EOL . 'Total time: ' . $this->pdo->log->primary($this->consoleTools->convertTime($totalTime)) . PHP_EOL));
     }
     return $nzbCount;
 }