/** * Usuwa te rekordy z tabeli _tmpRecord, dla których sesja już na pewno wygasła. * Usuwa też przypisane do tych rekordów pliki. */ public function clean() { $calendar = new Calendar(); $time = $calendar->addSeconds(CoreUtils::getDateTime(), -CoreConfig::get('Cron', 'tmpRecordOldAgeSeconds')); $tmpRecordDAO = new TmpRecordDAO(); $oldRecords = $tmpRecordDAO->getOldRecords($time, CoreConfig::get('Cron', 'tmpRecordsToDeletePerExecution')); $fileDAO = new FileDAO(); foreach ($oldRecords as $record) { if ($this->isForDeletion($record)) { $files = $fileDAO->getListByRecord('_tmpRecord', $record['id']); foreach ($files as $file) { $fileDAO->delete($file); } $tmpRecordDAO->delete($record); } } }
protected function assignTmpRecordFilesToPermanentRecord() { // 1. przeniesienie wszystkich plików z tmpRecordu do rekordu docelowego; // tych plików i tak na pewno nie ma w $this->fileList, trzeba je dopiero wczytać. $files = $this->fileDAO->getListByRecord('_tmpRecord', $this->tmpRecord['id']); foreach ($files as $file) { $file['recordType'] = $this->getRecordType(); $file['recordId'] = $this->record['id']; $this->fileDAO->save($file); } // 2. usunięcie tmpRecord $this->tmpRecordDAO->delete($this->tmpRecord); }
protected function getBaseRecord() { $recordType = $this->form->getField('recordType')->getValue(); $tmpId = $this->form->getField('_tmpId')->getValue(); if (!empty($tmpId)) { $dao = new TmpRecordDAO(); $record = $dao->getRecordById($tmpId); if (empty($record['id']) || $record['recordType'] != $recordType) { return null; } return $record; } else { $daoClass = strtoupper(substr($recordType, 0, 1)) . substr($recordType, 1) . 'DAO'; $dao = new $daoClass(); $id = $this->form->getField('id')->getValue(); $record = $dao->getRecordById($id); if (empty($record['id']) || !$this->isValidBaseRecord($recordType, $record)) { return null; } return $record; } }