Exemple #1
0
 /**
  * Create a webhook from request data.
  *
  * https://apidocs.mailchimp.com/webhooks/
  *
  * @param  array                             $data Request data
  * @return \Tev\TevMailchimp\Webhook\Webhook
  *
  * @throws \Exception If failed to instantiate webhook due to invalid data
  */
 public function create($data)
 {
     try {
         return new Webhook($this->getType($data), $this->getFiredAt($data), $this->getData($data), $this->getMergeFields($data));
     } catch (Exception $e) {
         $this->logger->error('Hook parsing failed', ['error' => $e->getMessage(), 'hook_data' => $data]);
         throw $e;
     }
 }
 /**
  * Download all lists from Mailchimp.
  *
  * @return void
  */
 public function listsCommand()
 {
     $this->outputLine('<info>Downloading lists...</info>');
     try {
         $lists = $this->mailchimpService->downloadLists();
         foreach ($lists as $l) {
             $this->outputLine("<comment>- {$l->getMcListId()} downloaded</comment>");
         }
         $this->outputLine('<info>complete</info>');
         $this->logger->info('Lists downloaded successfully via CLI');
     } catch (Exception $e) {
         $this->outputLine("<error>Error: {$e->getMessage()}</error>");
         $this->logger->error('Lists failed to download via CLI', ['message' => $e->getMessage()]);
     }
 }
 /**
  * The actual processing TASK
  *
  * Should return an array with database properties for sys_file_metadata to write
  *
  * @param File $file
  * @param array $previousExtractedData optional, contains the array of already extracted data
  * @return array
  */
 public function extractMetaData(File $file, array $previousExtractedData = [])
 {
     $metadata = [];
     try {
         if (!class_exists('ColorThief\\ColorThief')) {
             throw new \RuntimeException('Class ColorThief\\ColorThief does not exist', 1470749087524);
         }
         $path = $file->getForLocalProcessing();
         $averageColor = ColorThief::getColor($path);
         if (!is_array($averageColor)) {
             throw new \RuntimeException('$averageColor is not an array', 1470749109020);
         }
         if (count($averageColor) !== 3) {
             throw new \RuntimeException('$averageColor is an array, but has less than 3 items', 1470749136303);
         }
         $r = dechex((int) $averageColor[0]);
         $g = dechex((int) $averageColor[1]);
         $b = dechex((int) $averageColor[2]);
         $metadata['average_color'] = '#' . $r . $g . $b;
         $this->logger->debug(sprintf('Extracted average color "%s"', $metadata['average_color']), ['file' => $file->getUid()]);
     } catch (\Exception $e) {
         $this->logger->error($e->getCode() . ': ' . $e->getMessage(), ['file' => $file->getUid()]);
     }
     return $metadata;
 }
Exemple #4
0
 /**
  * Geocode a raw string to a lat/lng value.
  *
  * @param  string  $details  Geocode string
  * @return  array  Hash containing lat and lng. Both will be null if geocoding failed
  * @throws  \Exception  If API key is not set
  */
 public function geocode($details)
 {
     $geo = $this->createGeocoder();
     try {
         $coords = $geo->geocode($details)->first()->getCoordinates();
         return ['lat' => $coords->getLatitude(), 'lng' => $coords->getLongitude()];
     } catch (Exception $e) {
         $this->logger->error('Error geocoding details', ['exception_message' => $e->getMessage(), 'submitted_details' => $details]);
         return ['lat' => null, 'lng' => null];
     }
 }
 /**
  * Unsubcribe the given email address from the given list.
  *
  * @param  string                               $email Email to unsubscribe from list
  * @param  \Tev\TevMailchimp\Domain\Model\Mlist $list  List to unsubscribe email from
  * @return void
  */
 public function unsubscribeFromList($email, Mlist $list)
 {
     try {
         $curStatus = $this->getSubscriptionStatus($email, $list);
         if ($curStatus === 'subscribed' || $curStatus === 'pending' || $curStatus === 'cleaned') {
             $this->mc->updateMember($list->getMcListId(), $this->getMailchimpId($email), ['status' => 'unsubscribed']);
         }
     } catch (Exception $e) {
         $this->logger->error('MC API exception during unsubscribeFromList', ['message' => $e->getMessage(), 'email' => $email, 'list_uid' => $list->getUid(), 'mc_list_id' => $list->getMcListId()]);
         throw $e;
     }
 }
 /**
  * Import extension from file.
  *
  * @param string  $file      Path to t3x file
  * @param string  $location  Where to import the extension. System = typo3/sysext, Global = typo3/ext, Local = typo3conf/ext
  * @param boolean $overwrite Overwrite the extension if already exists
  *
  * @return void
  */
 public function importCommand($file, $location = 'Local', $overwrite = FALSE)
 {
     try {
         $data = $this->extensionApiService->importExtension($file, $location, $overwrite);
         $message = sprintf('Extension "%s" has been imported!', $data['extKey']);
         $this->outputLine($message);
         $this->logger->info($message);
     } catch (Exception $e) {
         $this->outputLine($e->getMessage());
         $this->logger->error($e->getMessage());
         $this->quit(1);
     }
 }
 /**
  * Start password reset
  *
  * @param string $username Username of a user
  * @return void
  *
  * @validate $username NotEmpty
  */
 public function startPasswordResetAction($username)
 {
     $user = $this->frontendUserRepository->findOneByUsername($username);
     // Forbid password reset if there is no password or password property,
     // e.g. if the user has not completed a special registration process
     // or is supposed to authenticate in some other way
     $password = ObjectAccess::getPropertyPath($user, 'password');
     if ($password === NULL) {
         $this->logger->error('Failed to initiate password reset for user "' . $username . '": no password present');
         $this->addLocalizedFlashMessage('resetPassword.failed.nopassword', NULL, FlashMessage::ERROR);
         $this->redirect('showPasswordResetForm');
     }
     $hash = md5(GeneralUtility::generateRandomBytes(64));
     $token = array('uid' => $user->getUid(), 'hmac' => $this->hashService->generateHmac($password));
     $tokenLifetime = $this->getSettingValue('passwordReset.token.lifetime');
     // Remove possibly existing reset tokens and store new one
     $this->tokenCache->flushByTag($user->getUid());
     $this->tokenCache->set($hash, $token, array($user->getUid()), $tokenLifetime);
     $expiryDate = new \DateTime(sprintf('now + %d seconds', $tokenLifetime));
     $hashUri = $this->uriBuilder->setTargetPageUid($this->getSettingValue('passwordReset.page'))->setUseCacheHash(FALSE)->setCreateAbsoluteUri(TRUE)->uriFor('showPasswordResetForm', array('hash' => $hash));
     /** @var \PAGEmachine\Hairu\Domain\DTO\PasswordResetRequestTransferObject $passwordResetRequestTransferObject */
     $passwordResetRequestTransferObject = GeneralUtility::makeInstance('PAGEmachine\\Hairu\\Domain\\DTO\\PasswordResetRequestTransferObject');
     $passwordResetRequestTransferObject->setUser($user);
     $passwordResetRequestTransferObject->setHash($hash);
     $passwordResetRequestTransferObject->setHashUri($hashUri);
     $passwordResetRequestTransferObject->setExpiryDate($expiryDate);
     $actionVariables = array('user' => $user, 'hash' => $hash, 'hashUri' => $hashUri, 'expiryDate' => $expiryDate);
     $this->view->assignMultiple($actionVariables);
     /** @var \TYPO3\CMS\Core\Mail\MailMessage $message */
     $message = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $message->setFrom($this->getSettingValue('passwordReset.mail.from'))->setTo($user->getEmail())->setSubject($this->getSettingValue('passwordReset.mail.subject'));
     $this->request->setFormat('txt');
     $message->setBody($this->view->render('passwordResetMail'), 'text/plain');
     $this->request->setFormat('html');
     $message->addPart($this->view->render('passwordResetMail'), 'text/html');
     $mailSent = FALSE;
     $passwordResetRequestTransferObject->setMessage($message);
     $this->emitBeforePasswordResetMailSendSignal($passwordResetRequestTransferObject);
     try {
         $mailSent = $message->send();
     } catch (\Swift_SwiftException $e) {
         $this->logger->error($e->getMessage());
     }
     if ($mailSent) {
         $this->addLocalizedFlashMessage('resetPassword.started', NULL, FlashMessage::INFO);
     } else {
         $this->addLocalizedFlashMessage('resetPassword.failed.sending', NULL, FlashMessage::ERROR);
     }
     $this->redirect('showPasswordResetForm');
 }
 /**
  * Create an empty record below the existing one
  *
  * @param array $row old plugin row
  * @return int uid of the new record
  */
 protected function createPluginBelowExisting(array $row)
 {
     $data = array();
     $data['tt_content']['NEW'] = array('hidden' => 1, 'pid' => $row['uid'] * -1);
     /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler */
     $dataHandler = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
     $dataHandler->start($data, array());
     $dataHandler->admin = 1;
     $dataHandler->process_datamap();
     if (!empty($dataHandler->errorLog)) {
         $this->logger->error('Error(s) while creating the empty content element');
         foreach ($dataHandler->errorLog as $log) {
             $this->logger->error($log);
         }
     }
     return (int) $dataHandler->substNEWwithIDs['NEW'];
 }
 /**
  * Unlocks the backend access by deleting the lock file
  */
 public function unlockCommand()
 {
     if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
         unlink(PATH_typo3conf . 'LOCK_BACKEND');
         if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
             $message = 'ERROR: Could not remove lock file \'typo3conf/LOCK_BACKEND\'!';
             $this->outputLine($message);
             $this->logger->error($message);
             $this->quit(1);
         } else {
             $message = 'Removed lock file \'typo3conf/LOCK_BACKEND\'';
             $this->outputLine($message);
             $this->logger->info($message);
         }
     } else {
         $message = 'No lock file \'typo3conf/LOCK_BACKEND\' was found, hence no lock could be removed.';
         $this->outputLine($message);
         $this->logger->info($message);
         $this->quit(1);
     }
 }
 /**
  * Database compare.
  * Leave the argument 'actions' empty or use "help" to see the available ones
  *
  * @param string $actions List of actions which will be executed
  * @param bool   $dry
  */
 public function databaseCompareCommand($actions = '', $dry = FALSE)
 {
     if ($actions === 'help' || strlen($actions) === 0) {
         $actions = $this->databaseApiService->databaseCompareAvailableActions();
         foreach ($actions as $number => $action) {
             $this->outputLine('  - ' . $action . ' => ' . $number);
         }
         $this->quit();
     }
     $result = $this->databaseApiService->databaseCompare($actions, $dry);
     if ($dry) {
         $this->outputLine('DB compare would execute the following queries:');
         foreach ($result as $key => $set) {
             $this->outputLine(sprintf('### Action: %s ###', $key));
             $this->outputLine('===================================');
             $this->logger->info(sprintf('### Action: %s ###', $key));
             $this->logger->info('===================================');
             foreach ($set as $line) {
                 $this->outputLine($line);
                 $this->logger->info($line);
             }
             $this->outputLine(LF);
         }
         $this->logger->info('DB compare executed in dry mode');
     } else {
         if (empty($result)) {
             $message = 'DB has been compared';
             $this->outputLine($message);
             $this->logger->info($message);
         } else {
             $message = sprintf('DB could not be compared, Error(s): %s', array(LF . implode(LF, $result)));
             $this->outputLine($message);
             $this->logger->error($message);
             $this->quit(1);
         }
     }
 }
Exemple #11
0
 /**
  * Remove temporary file.
  *
  * @param string $filePath
  */
 protected function removeTemporaryFile($filePath)
 {
     if (!GeneralUtility::unlink_tempfile($filePath)) {
         $this->logger->error('Failed to remove file', array('filepath' => $filePath));
     }
 }