/** * Tests that set and get Items files return the same. */ public function test_set_and_get_items_return_the_same() { $report = new Report\Report(); $items = array('a' => 'b'); $report->setItems($items); $this->assertEquals($items, $report->getItems()); }
/** * Write the report to the filesystem so we can reuse it * at a later stace when we invoke Redbox\Scan\ScanService's scan() method. * * @param Report|null $report * @return bool */ public function write(Report $report = null) { if ($report) { $scandata = array('name' => $report->getName(), 'path' => $report->getPath()); /* Step 1. Update the scan. */ $sql = sprintf("UPDATE `scan` SET `name`='%s', `path`='%s', `scandate`=NOW()", $this->real_escape_string($scandata['name']), $this->real_escape_string($scandata['path'])); $this->query($sql); if ($this->affected_rows > 0) { $items = $report->getItems(); if (count($items) > 0) { /* Step 2. Delete old items */ $sql = sprintf("DELETE FROM `scanitems` WHERE `scanid`='%s'", self::SCAN_ID); $this->query($sql); /* Step 3. Insert the new items */ foreach ($items as $path => $item) { foreach ($item as $filename => $md5hash) { $sql = sprintf("INSERT INTO `scanitems` SET `scanid`='%s', `itemfolder`='%s', `itemname`='%s', `md5hash`='%s'", self::SCAN_ID, $this->real_escape_string($path), $this->real_escape_string($filename), $this->real_escape_string($md5hash)); $this->query($sql); } } } } return false; } return false; }