/** * action update * * @param Tx_Contentstage_Domain_Model_Review $review * @param array $reviewers Array of be_user ids * @return void */ public function updateAction(Tx_Contentstage_Domain_Model_Review $review, array $reviewers = array()) { $this->checkPermission(); try { $this->mapReviewers($reviewers, iterator_to_array($review->getReviewed())); } catch (Exception $e) { $this->log->log($this->translate('error.' . $e->getCode(), array($e->getMessage())) ?: $e->getMessage(), Tx_CabagExtbase_Utility_Logging::ERROR); $this->redirect('compare', 'Content'); } // at the moment, it is not possible to inject a storage object at creation, so we have to cheat a bit $tempData = t3lib_div::_GP('tx_contentstage_web_contentstagestage_temp'); if (!$review->getPushPageChanges() && !empty($tempData['review']['dbrecord']) && count($tempData['review']['dbrecord']) > 0) { $converter = $this->objectManager->get('Tx_Contentstage_Property_TypeConverter_DbrecordConverter'); $review->setDbrecord($converter->convertFrom($tempData['review']['dbrecord'], 'Tx_Extbase_Persistence_ObjectStorage<Tx_Contentstage_Domain_Model_Dbrecord>')); } $this->reviewRepository->update($review); $this->persistenceManager->persistAll(); $this->log->log($this->translate('review.update.success'), Tx_CabagExtbase_Utility_Logging::OK); if ($this->reviewConfiguration['autoReviewIfSelf']) { $found = $review->getActiveReviewed($this->activeBackendUser); if ($found !== null && $found->getState() === Tx_Contentstage_Domain_Model_State::FRESH) { // the action will redirect to compare action and thus prevent the initial mail sent and only sends a "changed" mail $this->reviewedAction($review, $this->translate('review.submit.ok'), true); } } $this->sendReviewMailAndLog('changed', $review); $this->redirect('compare', 'Content'); }
/** * Sends a mail concerning a review and logs directly if the mail was sent. * * @param string $key Typoscript key under where to find the configuration. * @param Tx_Contentstage_Domain_Model_Review $review The review to send the mail for. * * @return boolean Whether or not the mail was sent. */ protected function sendReviewMailAndLog($key, Tx_Contentstage_Domain_Model_Review $review = null) { $pageTS = $this->getPageTS(); $tsKey = 'review' . ucfirst($key); if (empty($key) || !isset($pageTS['mails'][$tsKey]) || $review === null) { $this->log->log($this->translate('info.review.mail.error'), Tx_CabagExtbase_Utility_Logging::WARNING); return false; } $configuration = t3lib_div::array_merge_recursive_overrule($pageTS['mails']['default'], $pageTS['mails'][$tsKey]); $recipients = array(); if (!empty($configuration['sendToReviewers'])) { $recipients = $review->getRecipients(!empty($this->reviewConfiguration['sendMailToCurrentUser'])); } $ok = $this->sendMail($tsKey, $recipients, array('review' => $review)); if ($ok) { $this->log->log($this->translate('info.review.mail.success'), Tx_CabagExtbase_Utility_Logging::OK); } else { $this->log->log($this->translate('info.review.mail.error'), Tx_CabagExtbase_Utility_Logging::WARNING); } return $ok; }
/** * @param Tx_Contentstage_Domain_Model_Review $review the review to take the records from * @param string $table The table to query (CAN ONLY BE A SINGLE TABLE!). * @param string $fields The fields to get (* by default). * @param string $where The where condition (empty by default). * @param string $groupBy Group the query IMPORTANT: not used in this version. * @param string $orderBy Order to use on the query (uid ASC by default). * @param string $limit Limit the query. * @param string $idFields The ID fields of the table. * @return Tx_Contentstage_Domain_Repository_Result The result object. */ public function findReviewRecords(Tx_Contentstage_Domain_Model_Review $review, $table, $fields = '*', $where = '', $groupBy = '', $orderBy = 'uid ASC', $limit = '') { list($actualTable) = t3lib_div::trimExplode(' ', $table); // this is only needed in this scope but could be calculated hundreds of times, so static makes sense here static $tables; if (empty($tables) && !is_array($tables)) { foreach ($review->getDbrecord() as $dbrecord) { $dbecordTables[$dbrecord->getTablename()] = true; } // assign at the end $tables = $dbecordTables; } if (!isset($tables[$actualTable]) && !isset($tables[$table]) || substr($table, -3) !== '_mm' && !$this->tcaObject->isValidTca($table)) { $result = $this->objectManager->create('Tx_Contentstage_Domain_Repository_EmptyResult'); $result->setRepository($this); $result->setTable($table); return $result; } $result = $this->objectManager->create('Tx_Contentstage_Domain_Repository_Result'); $result->setRepository($this); $result->setTable($table); $uids = array(); foreach ($review->getDbrecord() as $record) { $uids[] = $record->getRecorduid(); } if (empty($uids)) { $whereParts = array('1 <> 1'); } else { $whereParts = array('uid IN (' . implode(',', $uids) . ')'); } if (!empty($where)) { $whereParts[] = '(' . $where . ')'; } $query = $this->db->SELECTquery($fields, $table, implode(' AND ', $whereParts), $groupBy, $orderBy, $limit); // this slows the process down imensely! //$this->log->log($query, Tx_CabagExtbase_Utility_Logging::INFORMATION); $resource = $this->db->sql_query($query); if (!$resource || $this->db->sql_error()) { throw new Exception($this->db->sql_error() . ' [Query: ' . $this->db->SELECTquery($fields, $table, implode(' AND ', $whereParts), $groupBy, $orderBy, $limit) . ']', self::ERROR_GET); } $result->setResource($resource); $result->setQuery($query); return $result; }