/** * Save * * @throws Exception * @return array */ public final function save() { if (empty($this->_table)) { throw new Exception('Table is not specified'); } // Update if ($this->_stored) { $this->_table->updateRow($this); } else { $this->_table->insertRow($this); } return $this->getPrimaryKey(); }
/** * Update file row * * @param string $pathname * @param SeekR_Row $row * @param array $newValues */ protected final function _updateFileRow($pathname, SeekR_Row $row, array $newValues) { // Data $oldValues = $row->toArray(); if ($oldValues['status'] == self::STATUS_REMOVED) { $operation = self::OPERATION_NEW; $oldValues = array(); } else { $operation = self::OPERATION_MODIFIED; } $difference = array_diff_assoc($newValues, $oldValues); $scanID = $this->_scanRow->scanID; // Changed if ($difference || $operation == self::OPERATION_NEW) { // Has history row for this scan if ($historyRow = $this->_fileHistoryTable->fetchRow(array('fileID' => $row->fileID, 'scanID' => $scanID))) { $historyRow->setFromArray($difference)->save(); } else { if ($operation != self::OPERATION_NEW) { fwrite(STDOUT, "\t{$pathname} has been changed.\n"); } $this->_fileHistoryTable->createRow(array('fileID' => $row->fileID, 'scanID' => $scanID, 'operation' => $operation, 'dateOnly' => count($difference) == 1 && isset($difference['modifyDate']) ? 'yes' : 'no') + $difference)->save(); } // Row update $row->setFromArray(array('modifyScanID' => $scanID, 'status' => self::STATUS_ACTIVE) + $difference); } }