logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); parent::__construct($mail, $configuration, $settings, $formSubmitted, $actionMethodName, $contentObject); } /** * Finisher which does all the magic */ public function talentePoolFinisher() { $fields = $this->getMail()->getAnswersByFieldMarker(); $insert = [ 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'pid' => (int)$this->configuration['pid'], 'hidden' => 1 ]; foreach ((array)$this->configuration['fieldMapping'] as $from => $to) { $insert[$to] = $this->getFieldValue($fields, $from); } $table = 'tx_example_domain_model_talent'; $db = $this->getDatabaseConnection(); $db->exec_INSERTquery($table, $insert); $uploadFile = $this->getFieldValue($fields, 'upload'); if (!empty($uploadFile)) { $newRecordId = $db->sql_insert_id(); $copiedLocation = $this->handleUpload($uploadFile); if ($copiedLocation) { $fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($copiedLocation); if (!is_null($fileOrFolderObject)) { $sysFileId = $fileOrFolderObject->getUid(); $insert = [ 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'pid' => (int)$this->configuration['pid'], 'uid_local' => $sysFileId, 'uid_foreign' => $newRecordId, 'tablenames' => $table, 'fieldname' => 'foto' ]; $db->exec_INSERTquery('sys_file_reference', $insert); $db->exec_UPDATEquery($table, 'uid=' . $newRecordId, ['foto' => 1]); } } } } protected function handleUpload($file = '') { if (empty($file)) { $this->logger->debug('no file'); return ''; } // this could be nicer for sure $file = trim($file, '[]"'); $path = PATH_site . '/uploads/tx_powermail/' . $file; $target = '/fileadmin/' . trim($this->configuration['path'], '/') . '/' . $file; $targetAbsolute = PATH_site . $target; if (!is_file($path)) { $this->logger->debug('no file for ' . $file); return ''; } @copy($path, $targetAbsolute); GeneralUtility::fixPermissions($targetAbsolute); return $targetAbsolute; } /** * @param array $fields * @param string $name * @return string */ protected function getFieldValue(array $fields, $name) { $field = $fields[$name]; if (!is_null($field)) { /** @var Answer $field */ return $field->getRawValue(); } return ''; } /** * @return DatabaseConnection */ protected function getDatabaseConnection() { return $GLOBALS['TYPO3_DB']; } }