/**
  * Creates users based on given array.
  *
  * @param $packageKey
  * @param $configuration
  * @param $configurationController
  */
 public function createCLIUsers($packageKey, $configuration, $configurationController)
 {
     // Only create CLI users on configuration save of template bootstrap package
     if (TemplateBootstrapUtility::getPackageKey() !== $packageKey) {
         return;
     }
     // Get cli user names that supposedly need to be created
     $userNames = GeneralUtility::trimExplode(',', $configuration['createCLIUsers']['value']);
     foreach ($userNames as $userName) {
         $cliUserName = '******' . $userName;
         $cliUserNameQuoted = $GLOBALS['TYPO3_DB']->fullQuoteStr($cliUserName, 'be_users');
         // Check, if user exists already
         $userExistsResult = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'be_users', 'username='******'TYPO3_DB']->sql_error()) {
             PostInstallInfoLogger::log('Failed to check whether BE user "' . $cliUserName . '" exists. Therefore cancelled. Error: ' . $GLOBALS['TYPO3_DB']->sql_error(), PostInstallInfoLogger::MESSAGE_TYPE_SYSTEM_ERROR);
             continue;
         }
         // User exists - (re-) activate, in case it has been deleted previously
         if ($GLOBALS['TYPO3_DB']->sql_num_rows($userExistsResult) > 0) {
             $existingUserRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($userExistsResult);
             if ($existingUserRow['deleted']) {
                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_users', 'uid=' . $existingUserRow['uid'], array('deleted' => 0));
                 $updatedError = $GLOBALS['TYPO3_DB']->sql_error();
                 if ($updatedError) {
                     PostInstallInfoLogger::log('Failed to reactivate (un-delete) BE user "' . $cliUserName . '". Error: ' . $GLOBALS['TYPO3_DB']->sql_error(), PostInstallInfoLogger::MESSAGE_TYPE_SYSTEM_ERROR);
                 } else {
                     PostInstallInfoLogger::log('Reactivated (un-deleted) BE user "' . $cliUserName . '"' . $GLOBALS['TYPO3_DB']->sql_error(), PostInstallInfoLogger::MESSAGE_TYPE_OK);
                 }
             }
             // Skip to next user(name) as this one was handled by simply reactivating it.
             continue;
         }
         // Create user
         $saltedPassword = md5($this->getRandomPassword());
         if (PackageManager::isPackageActive('saltedpasswords')) {
             $saltingInstance = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance();
             $saltedPassword = $saltingInstance->getHashedPassword($saltedPassword);
         }
         $createdSqlResult = $GLOBALS['TYPO3_DB']->exec_INSERTquery('be_users', array('crdate' => time(), 'tstamp' => time(), 'cruser_id' => $GLOBALS['BE_USER']->user['uid'], 'username' => $cliUserName, 'password' => $saltedPassword));
         // Failed to create user
         if ($GLOBALS['TYPO3_DB']->sql_error()) {
             PostInstallInfoLogger::log('Failed to create BE user "' . $cliUserName . '". Error: ' . $GLOBALS['TYPO3_DB']->sql_error(), PostInstallInfoLogger::MESSAGE_TYPE_SYSTEM_ERROR);
             // User successfully created
         } else {
             PostInstallInfoLogger::log('Created BE user "' . $cliUserName . '"', PostInstallInfoLogger::MESSAGE_TYPE_OK);
         }
     }
     // foreach user that needs to be created
 }
 /**
  * Evaluate condition
  *
  * @param array $conditionParameters
  * @return bool
  */
 public function matchCondition(array $conditionParameters)
 {
     $result = FALSE;
     if (!empty($conditionParameters)) {
         $packageKey = TemplateBootstrapUtility::getPackageKey();
         $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$packageKey]);
         if (!empty($conditionParameters) && substr($conditionParameters[0], 0, 1) === '=') {
             $conditionParameters[0] = trim(substr($conditionParameters[0], 1));
         }
         if (!empty($conditionParameters) && strtolower($conditionParameters[0]) === strtolower($extensionConfiguration['environment'])) {
             $result = TRUE;
         }
     }
     return $result;
 }
 /**
  * Renders and writes configuration that needs to go into AdditionalConfiguration.php
  *
  * @param $packageKey
  * @param $configuration
  */
 public function writeAdditionalConfiguration($packageKey, $configuration)
 {
     // Only write additional configuration on configuration save of template bootstrap package
     if (TemplateBootstrapUtility::getPackageKey() !== $packageKey) {
         return;
     }
     global $BE_USER;
     $fileContentLines = array();
     // rewrite configuration, if necessary.
     $enableCustomErrorHandler = intval($configuration['enableCustomErrorHandling']['value']);
     if ($enableCustomErrorHandler) {
         $errorHandlerReference = 'USER_FUNCTION:typo3conf/ext/' . $packageKey . '/Classes/Utility/PageNotFoundHandler.php:Staempfli\\TemplateBootstrap\\Utility\\PageNotFoundHandler->pageNotFound';
         if ($errorHandlerReference !== $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling']) {
             $fileContentLines[] = '$GLOBALS[\'TYPO3_CONF_VARS\'][\'FE\'][\'pageNotFound_handling\'] = \'' . $errorHandlerReference . '\';';
         }
     }
     // trustedHostsPattern
     if (intval($configuration['generateTrustedHostsPattern']['value'])) {
         $finalPattern = 'SERVER_NAME';
         $domainsResult = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_domain', NULL);
         if ($GLOBALS['TYPO3_DB']->sql_num_rows($domainsResult)) {
             $domainNames = array();
             while ($domainRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($domainsResult)) {
                 $domainNames[] = str_replace('.', '\\.', $domainRecord['domainName']);
             }
             $finalPattern = '^(' . implode('|', $domainNames) . ')$';
         }
         if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] !== $finalPattern) {
             $fileContentLines[] = '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'trustedHostsPattern\'] = \'' . $finalPattern . '\';';
         }
     }
     // Nothing to write?
     // abort.
     if (!count($fileContentLines)) {
         return;
     }
     // Enclose content with php tags & comment
     array_unshift($fileContentLines, '# Automatically (re-)written by extension "' . $packageKey . '". (' . date('d.m.Y H:i:s') . ')');
     array_unshift($fileContentLines, '<?php');
     $fileContentLines[] = ' ?>';
     // Write file
     $file = @fopen(PATH_typo3conf . '/AdditionalConfiguration.php', 'a');
     $written = false;
     if ($file) {
         $written = @fwrite($file, implode(chr(10), $fileContentLines));
         @fclose($file);
     }
     // Write log
     if ($written) {
         PostInstallInfoLogger::log('AdditionalConfiguration.php updated.', PostInstallInfoLogger::MESSAGE_TYPE_OK, 20);
     } else {
         PostInstallInfoLogger::log('Attempted to extend AdditionalConfiguration.php, but failed!', PostInstallInfoLogger::MESSAGE_TYPE_SYSTEM_ERROR, 20);
     }
 }
 /**
  * Gets messages for the 'SystemInformationToolbarItem' signal slot specifically.
  * @param $originalInformation
  * @param $class
  * @return array|null
  */
 public function getTemplateBootstrapLogMessages($originalInformation, $class)
 {
     global $BE_USER;
     $packageKey = TemplateBootstrapUtility::getPackageKey();
     // Get last backend log access timestamp as this lets us
     // filter out any old(er) messages.
     if (isset($BE_USER->uc['systeminformation'])) {
         $systemInformationUc = json_decode($BE_USER->uc['systeminformation'], TRUE);
         if (isset($systemInformationUc['system_BelogLog']['lastAccess'])) {
             $lastSystemLogAccessTimestamp = $systemInformationUc['system_BelogLog']['lastAccess'];
         }
     }
     // Fall back to the last 24 hours.
     if (!isset($lastSystemLogAccessTimestamp)) {
         $lastSystemLogAccessTimestamp = time() - 3600 * 24;
     }
     // We can't use the extbase repository here as the required TypoScript may not be parsed yet
     $messagesResult = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_log', 'tstamp >= ' . $lastSystemLogAccessTimestamp . ' AND userid=' . $BE_USER->user['uid'] . ' AND details LIKE "' . self::getMessagePrefix($packageKey) . '%"', '', 'tstamp DESC');
     // Error getting messages
     if ($GLOBALS['TYPO3_DB']->sql_error()) {
         return NULL;
         // No messages found
     } elseif ($GLOBALS['TYPO3_DB']->sql_num_rows($messagesResult) === 0) {
         return NULL;
         // Render messages
     } else {
         $alreadyCoveredMessageTypes = array();
         $highestFoundSeverety = self::MESSAGE_TYPE_INFO;
         $finalMessages = array();
         while ($message = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($messagesResult)) {
             // Skip this message, if the 'message type' a.k.a. 'action' has already been
             // covered. P.e. only show latest entry about re-writing robots.txt
             if (in_array($message['action'], $alreadyCoveredMessageTypes)) {
                 continue;
             }
             $alreadyCoveredMessageTypes[] = $message['action'];
             // Track down highest severety over all found messages
             if ($highestFoundSeverety < $message['error']) {
                 $highestFoundSeverety = $message['error'];
             }
             // Get 'error' number as message type,
             // but override with registered message type in 'log_data' field.
             $displayMessageType = $message['error'];
             if ($message['log_data'] !== NULL) {
                 $logData = @unserialize($message['log_data']);
                 if (is_array($logData) && isset($logData['displayMessageType'])) {
                     $displayMessageType = $logData['displayMessageType'];
                 }
             }
             // Get message text & render HTML
             $messageDetails = str_replace(self::getMessagePrefix($packageKey), '', $message['details']);
             $finalMessages[] = '<li class="text-' . self::$MESSAGE_TYPE_TO_INFOSTATUS_MAP[$displayMessageType] . ' templatebootstrap-installlog-entry">' . $messageDetails . '</li>';
         }
         // Render whole message block
         $allMessagesString = '<span class="templatebootstrap-installlog-title">Extension manager messages for ' . $packageKey . ':</span>' . '<ul class="templatebootstrap-installlog">' . implode('', $finalMessages) . '</ul>' . '<a href="' . BackendUtility::getModuleUrl('system_BelogLog') . '"><span class="text-muted">(Dismiss this by visiting the backend log - click this message.)</span></a>';
         // Return messages as one.
         // Note: This return structure may not be changed! This is the format as requested
         // by the API. Also, adding any subarrays will not work!
         return array(array('module' => 'system_BelogLog', 'count' => count($finalMessages), 'status' => self::$MESSAGE_TYPE_TO_INFOSTATUS_MAP[$highestFoundSeverety], 'text' => $allMessagesString));
     }
     // if db query successfully executed with > 0 results
 }