} if (array_search('--template-lang', $argv) !== false) { $strSourceLanguage = $argv[array_search('--template-lang', $argv) + 1]; } else { $strSourceLanguage = NarroLanguage::SOURCE_LANGUAGE_CODE; } if (array_search('--translation-lang', $argv) !== false) { $strTargetLanguage = $argv[array_search('--translation-lang', $argv) + 1]; } if (array_search('--user', $argv) !== false) { $intUserId = $argv[array_search('--user', $argv) + 1]; } $objUser = NarroUser::LoadByUserId($intUserId); if (!$objUser instanceof NarroUser) { NarroLogger::LogInfo(sprintf('User id=%s does not exist in the database, will try to use the anonymous user.', $intUserId)); $objUser = NarroUser::LoadAnonymousUser(); if (!$objUser instanceof NarroUser) { NarroLogger::LogInfo(sprintf('The anonymous user id=%s does not exist in the database.', $intUserId)); return false; } } QApplication::$User = $objUser; $objProject = NarroProject::Load($intProjectId); if (!$objProject instanceof NarroProject) { NarroLogger::LogInfo(sprintf('Project with id=%s does not exist in the database.', $intProjectId)); return false; } $objLanguage = NarroLanguage::LoadByLanguageCode($strTargetLanguage); if (!$objLanguage instanceof NarroLanguage) { NarroLogger::LogInfo(sprintf('Language %s does not exist in the database.', $strTargetLanguage)); return false;
public static function InitializeUser() { global $argv; if (QApplication::$Session->User) { QApplication::$User = QApplication::$Session->User; } elseif (is_array($argv) && array_search('--user', $argv) !== false) { QApplication::$User = NarroUser::LoadByUserId((int) $argv[array_search('--user', $argv) + 1]); } if (!QApplication::$User instanceof NarroUser) { QApplication::$User = NarroUser::LoadAnonymousUser(); QApplication::$Session->User = QApplication::$User; } if (!QApplication::$User instanceof NarroUser) { // @todo add handling here throw new Exception('Could not create an instance of NarroUser'); } }