public function testWarnAppendsStackTraceIfGivenAnError() { $message = 'an error occured'; $exception = new Exception('some error'); $this->logger->warn($message, $exception); $this->assertLogContainsStackTrace($exception); $this->assertLogContainsErrorMessage($exception, $message); }
/** * @throws Docman_FolderNotCreatedException */ private function createFolderWithRightAccessRights($folder_path, $project_unix_name) { if (!mkdir($folder_path)) { throw new Docman_FolderNotCreatedException("Folder {$folder_path} not created"); } $user = ForgeConfig::get('sys_http_user'); $this->backend->changeOwnerGroupMode($folder_path, $user, $user, 0700); $this->logger->info("Docman root folder for project {$project_unix_name} created"); }
public function activateMLEBForCompatibleProjects(BackendLogger $logger) { foreach ($this->getProjectsEligibleToMLEBExtensionActivation() as $project) { if ($this->activateMLEBForProject($project)) { $project_id = $project->getID(); $logger->info("Activated MLEB extension for project {$project_id}"); } } }
/** @see Logger::log() */ public function log($message, $level = Feedback::INFO) { $prefix = self::WF_PREFIX; if ($this->fingerprint) { $prefix .= "[{$this->fingerprint}] "; } $prefix .= $this->indentation_prefix; $this->backend_logger->log($prefix . $message, $level); }
/** @return Tracker */ private function importTrackerStructure() { try { return $this->xml_import->createFromXMLFile($this->project->getID(), $this->template_path); } catch (Exception $exception) { $logger = new BackendLogger(); $logger->error('Unable to create first kanban for ' . $this->project->getId() . ': ' . $exception->getMessage()); return; } }
/** * Process nightly job to send reminders * * @return Void */ public function process() { $logger = new BackendLogger(); $remiderFactory = $this->getDateReminderRenderer()->getDateReminderFactory(); $reminders = $remiderFactory->getTrackerReminders(false); foreach ($reminders as $reminder) { $logger->debug("[TDR] Processing reminder on " . $reminder->getField()->getName() . " (id: " . $reminder->getId() . ")"); $artifacts = $this->getArtifactsByreminder($reminder); if (count($artifacts) == 0) { $logger->debug("[TDR] No artifact match"); } foreach ($artifacts as $artifact) { $logger->debug("[TDR] Artifact #" . $artifact->getId() . " match"); $this->sendReminderNotification($reminder, $artifact); } } }
private function createDatabase($mediawiki_path) { $schema = strtr('plugin_mediawiki_' . $this->project_id, '-', '_'); $table_file = $mediawiki_path . '/maintenance/tables.sql'; $main_db = ForgeConfig::get('sys_dbname'); db_query('START TRANSACTION;'); try { $this->logger->info('Creating schema ' . $schema); $create_db = db_query_params('CREATE SCHEMA ' . $schema, array()); if (!$create_db) { throw new Exception('Error: Schema Creation Failed: ' . db_error()); } $this->logger->info('Updating mediawiki database.'); if (!file_exists($table_file)) { throw new Exception('Error: Couldn\'t find Mediawiki Database Creation File ' . $table_file); } $this->logger->info('Using schema: ' . $schema); $use_new_schema = db_query('USE ' . $schema); if (!$use_new_schema) { throw new Exception('Error: DB Query Failed: ' . db_error()); } $this->logger->info('Running db_query_from_file(' . $table_file . ')'); $add_tables = db_query_from_file($table_file); if (!$add_tables) { throw new Exception('Error: Mediawiki Database Creation Failed: ' . db_error()); } $this->logger->info('Updating list of mediawiki databases (' . $schema . ')'); db_query('USE ' . $main_db); $update = $this->dao->addDatabase($schema, $this->project_id); if (!$update) { throw new Exception('Error: Mediawiki Database list update failed: ' . mysql_error()); } } catch (Exception $e) { db_query('ROLLBACK;'); $this->logger->error($e->getMessage()); } db_query('COMMIT;'); $this->logger->info('Using schema: ' . $main_db); db_query('USE ' . $main_db); }
private function clearMediawikiCache(Project $project) { $schema = $this->getDao()->getMediawikiDatabaseName($project, false); $logger = new BackendLogger(); if ($schema) { $delete = $this->getDao()->clearPageCacheForSchema($schema); if (!$delete) { $logger->error('Project Clear cache: Can\'t delete mediawiki cache for schema: ' . $schema); } } else { $logger->error('Project Clear cache: Can\'t find mediawiki db for project: ' . $project->getID()); } }
/** * Process the nightly job to send reminder on artifact correponding to given criteria * * @param Array $params Hook params * * @return Void */ public function codendi_daily_start($params) { include_once 'Tracker/TrackerManager.class.php'; $trackerManager = new TrackerManager(); $logger = new BackendLogger(); $logger->debug("[TDR] Tuleap daily start event: launch date reminder"); return $trackerManager->sendDateReminder(); }
* (at your option) any later version. * * Tuleap is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Tuleap. If not, see <http://www.gnu.org/licenses/>. */ require_once 'pre.php'; require_once __DIR__ . '/../include/autoload.php'; $plugin_manager = PluginManager::instance(); $plugin = $plugin_manager->getPluginByName('proftpd'); if ($plugin && $plugin_manager->isPluginAvailable($plugin)) { $file_importer = new Tuleap\ProFTPd\Xferlog\FileImporter(new Tuleap\ProFTPd\Xferlog\Dao(), new Tuleap\ProFTPd\Xferlog\Parser(), UserManager::instance(), ProjectManager::instance(), $plugin->getPluginInfo()->getPropVal('proftpd_base_directory')); $file_importer->import($argv[1]); echo "{$file_importer->getNbImportedLines()} lines imported" . PHP_EOL; $errors = $file_importer->getErrors(); $nb_errors = count($errors); if ($nb_errors) { $logger = new BackendLogger(); echo "{$nb_errors} errors" . PHP_EOL; foreach ($errors as $error) { $logger->error('[Proftpd][xferlog parse] ' . $error); echo "*** ERROR: " . $error . PHP_EOL; } } } else { echo "*** ERROR: proftpd plugin not available" . PHP_EOL; }
/** * Check that threshold is upper then percentage of users that will be suspended * * @param int $nbr_users_to_suspend * @param int $nbr_all_users * * @return Boolean * */ public function checkThreshold($nbr_users_to_suspend, $nbr_all_users) { if ($nbr_users_to_suspend == 0 || $nbr_all_users == 0) { return true; } $percentage_users_to_suspend = $nbr_users_to_suspend / $nbr_all_users * 100; $threshold_users_suspension = $this->ldap->getLDAPParam('threshold_users_suspension'); $logger = new BackendLogger(); if ($percentage_users_to_suspend <= $threshold_users_suspension) { $logger->info("[LDAP] Percentage of suspended users is ( " . $percentage_users_to_suspend . "% ) and threshold is ( " . $threshold_users_suspension . "% )"); $logger->info("[LDAP] Number of suspended users is ( " . $nbr_users_to_suspend . " ) and number of active users is ( " . $nbr_all_users . " )"); return true; } else { $logger->warn("[LDAP] Users not suspended: the percentage of users to suspend is ( " . $percentage_users_to_suspend . "% ) higher then threshold ( " . $threshold_users_suspension . "% )"); $logger->warn("[LDAP] Number of users not suspended is ( " . $nbr_users_to_suspend . " ) and number of active users is ( " . $nbr_all_users . " )"); return false; } }
/** * Send Date reminder * * @return Void */ public function sendDateReminder() { $logger = new BackendLogger(); $logger->debug("[TDR] Start processing date reminders"); $trackers = $this->getTrackersHavingDateReminders(); foreach ($trackers as $tracker) { $logger->debug("[TDR] Processing date reminders for tracker " . $tracker->getProject()->getUnixName() . " / " . $tracker->getItemName() . " (id: " . $tracker->getId() . ")"); $dateReminderManager = new Tracker_DateReminderManager($tracker); $dateReminderManager->process(); } $logger->debug("[TDR] End processing date reminders"); }
/** * @return Tracker (only the structure) */ public function createTV5FromTV3(Project $project, $name, $description, $itemname, ArtifactType $tv3) { $dao = new Tracker_Migration_V3_Dao(); $logger = new BackendLogger(ForgeConfig::get('codendi_log') . '/' . Tracker_Migration_MigrationManager::LOG_FILE); $log_prefix = '[' . uniqid() . ']'; $logger->info("{$log_prefix} Start migration of tracker v3: " . $tv3->getID()); // 010 & 020 if ($id = $dao->create($project->getId(), $name, $description, $itemname, $tv3->getID())) { $logger->info("{$log_prefix} Tracker v5: " . $id); $logger->info("{$log_prefix} 030 Fieldset"); $fieldset_dao = new Tracker_Migration_V3_FieldsetsDao(); $fieldset_dao->create($tv3->getID(), $id); $logger->info("{$log_prefix} 040 Fields"); $field_dao = new Tracker_Migration_V3_FieldsDao(); $field_dao->create($tv3->getID(), $id); $logger->info("{$log_prefix} 045 & 046 Fields Default Values"); $fields_default_values_dao = new Tracker_Migration_V3_FieldsDefaultValuesDao(); $fields_default_values_dao->create($tv3->getID(), $id); $logger->info("{$log_prefix} 050 Reports"); $reports_dao = new Tracker_Migration_V3_ReportsDao(); $reports_dao->create($tv3->getID(), $id, $project->getId()); $logger->info("{$log_prefix} 060 RenderersTable"); $renderers_table_dao = new Tracker_Migration_V3_RenderersTableDao(); $renderers_table_dao->create($tv3->getID(), $id); $logger->info("{$log_prefix} 070 RenderersGraph"); $renderers_graph_dao = new Tracker_Migration_V3_RenderersGraphDao(); $renderers_graph_dao->create($tv3->getID(), $id); $logger->info("{$log_prefix} 075 PermissionsOnArtifactField"); $perms_on_artifact_dao = new Tracker_Migration_V3_PermissionsOnArtifactFieldDao(); $perms_on_artifact_dao->addPermissionsOnArtifactField($id); $logger->info("{$log_prefix} 080 AttachmentField"); $attachment_field_dao = new Tracker_Migration_V3_AttachmentFieldDao(); $attachment_field_dao->addAttachmentField($id); $logger->info("{$log_prefix} 085 ReferenceField"); $reference_dao = new Tracker_Migration_V3_ReferenceFieldDao(); $reference_dao->addReferenceField($id); $logger->info("{$log_prefix} 090 CCField"); $cc_dao = new Tracker_Migration_V3_CcFieldDao(); $cc_dao->addCCField($id); $logger->info("{$log_prefix} 220 Semantic"); $semantic_dao = new Tracker_Migration_V3_SemanticDao(); $semantic_dao->create($id); $logger->info("{$log_prefix} 250 Canned"); $canned_dao = new Tracker_Migration_V3_CannedDao(); $canned_dao->create($tv3->getID(), $id); $logger->info("{$log_prefix} 260 Fieldset stored as field"); $fieldset_dao->nowFieldsetsAreStoredAsField($id); $logger->info("{$log_prefix} 270 & 280 columns"); $columns_dao = new Tracker_Migration_V3_ColumnsDao(); $columns_dao->create($id); // 300 // useless because transitions already have default permissions $logger->info("{$log_prefix} 310 FieldPerms"); $field_perms_dao = new Tracker_Migration_V3_FieldPermsDao(); $field_perms_dao->create($tv3->getID(), $id); $logger->info("{$log_prefix} 320 FieldDependencies"); $field_dependencies_dao = new Tracker_Migration_V3_FieldDependenciesDao(); $field_dependencies_dao->addDependencies($tv3->getID(), $id); $logger->info("{$log_prefix} date reminders"); $reminder_dao = new Tracker_Migration_V3_RemindersDao(); $reminder_dao->create($tv3->getID(), $id); $logger->info("{$log_prefix} Complete"); return $this->tracker_factory->getTrackerById($id); } }
/** * Hook * * @params $params $params['login'] * $params['password'] * $params['auth_success'] * $params['auth_user_id'] * $params['auth_user_status'] */ function authenticate($params) { if ($GLOBALS['sys_auth_type'] == 'ldap') { try { $params['auth_success'] = false; $user = $this->getLdapUserManager()->authenticate($params['loginname'], $params['passwd']); if ($user) { $params['auth_user_id'] = $user->getId(); $params['auth_user_status'] = $user->getStatus(); $params['auth_success'] = true; } } catch (LDAP_UserNotFoundException $exception) { $GLOBALS['Response']->addFeedback(Feedback::ERROR, $exception->getMessage()); } catch (LDAP_AuthenticationFailedException $exception) { $logger = new BackendLogger(); $logger->info("[LDAP] User " . $params['loginname'] . " failed to authenticate"); } } }
/** * Process stored event */ function process() { /* @var $backendSystem BackendSystem */ $backendSystem = Backend::instance('System'); $backendAliases = Backend::instance('Aliases'); $backendSVN = Backend::instance('SVN'); $backendCVS = Backend::instance('CVS'); $backendMailingList = Backend::instance('MailingList'); //TODO: // User: unix_status vs status?? // Private project: if codeaxadm is not member of the project: check access to SVN (incl. ViewVC), CVS, Web... // CVS Watch? // TODO: log event in syslog? // TODO: check that there is no pending event??? What about lower priority events?? // First, force NSCD refresh to be sure that uid/gid will exist on next // actions $backendSystem->flushNscdAndFsCache(); // remove deleted releases and released files if (!$backendSystem->cleanupFRS()) { $this->error("An error occured while moving FRS files"); return false; } // Force global updates: aliases, CVS roots, SVN roots $backendAliases->setNeedUpdateMailAliases(); // Remove temporary files generated by aborted CVS commits $backendCVS->cleanup(); // Check mailing lists // (re-)create missing ML $mailinglistdao = new MailingListDao(); $dar = $mailinglistdao->searchAllActiveML(); foreach ($dar as $row) { $list = new MailingList($row); if (!$backendMailingList->listExists($list)) { $backendMailingList->createList($list->getId()); } // TODO what about lists that changed their setting (description, public/private) ? } $project_manager = ProjectManager::instance(); foreach ($project_manager->getProjectsByStatus(Project::STATUS_ACTIVE) as $project) { // Recreate project directories if they were deleted if (!$backendSystem->createProjectHome($project->getId())) { $this->error("Could not create project home"); return false; } if ($project->usesCVS()) { $backendCVS->setCVSRootListNeedUpdate(); if (!$backendCVS->repositoryExists($project)) { if (!$backendCVS->createProjectCVS($project->getId())) { $this->error("Could not create/initialize project CVS repository"); return false; } $backendCVS->setCVSPrivacy($project, !$project->isPublic() || $project->isCVSPrivate()); } $backendCVS->createLockDirIfMissing($project); // check post-commit hooks if (!$backendCVS->updatePostCommit($project)) { return false; } $backendCVS->updateCVSwriters($project->getID()); $backendCVS->updateCVSWatchMode($project->getID()); // Check ownership/mode/access rights $backendCVS->checkCVSMode($project); } if ($project->usesSVN()) { if (!$backendSVN->repositoryExists($project)) { if (!$backendSVN->createProjectSVN($project->getId())) { $this->error("Could not create/initialize project SVN repository"); return false; } $backendSVN->updateSVNAccess($project->getId()); $backendSVN->setSVNPrivacy($project, !$project->isPublic() || $project->isSVNPrivate()); $backendSVN->setSVNApacheConfNeedUpdate(); } else { $backendSVN->checkSVNAccessPresence($project->getId()); } $backendSVN->updateHooks($project); // Check ownership/mode/access rights $backendSVN->checkSVNMode($project); } } $logger = new BackendLogger(); if (is_file($logger->getFilepath())) { $backendSystem->changeOwnerGroupMode($logger->getFilepath(), ForgeConfig::get('sys_http_user'), ForgeConfig::get('sys_http_user'), 0640); } // If no codendi_svnroot.conf file, force recreate. if (!is_file($GLOBALS['svn_root_file'])) { $backendSVN->setSVNApacheConfNeedUpdate(); } try { EventManager::instance()->processEvent(Event::PROCCESS_SYSTEM_CHECK, array('logger' => $logger)); } catch (Exception $exception) { $this->error($exception->getMessage()); return false; } $this->expireRestTokens(UserManager::instance()); $this->done(); return true; }
private function generateLogWithException($message, Exception $exception = null) { return $this->backend_logger->generateLogWithException($message, $exception); }
/** * Log message in codendi_syslog * * @param string $message The error message that should be logged. * @param string $level The level of the message "info", "warn", ... * * @return boolean true on success or false on failure */ public function log($message, $level = 'info') { $logger = new BackendLogger(); return $logger->log($message, $level); }
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Tuleap is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Tuleap. If not, see <http://www.gnu.org/licenses/>. */ require 'pre.php'; $fd = fopen("php://stdin", "r"); $raw_mail = ""; while (!feof($fd)) { $raw_mail .= fread($fd, 1024); } fclose($fd); $logger = new BackendLogger(); $logger->info("Entering email gateway"); $recipient_factory = Tracker_Artifact_MailGateway_RecipientFactory::build(); $parser = new Tracker_Artifact_MailGateway_Parser($recipient_factory); $citation_sripper = new Tracker_Artifact_MailGateway_CitationStripper(); $mailgateway = new Tracker_Artifact_MailGateway_MailGateway($parser, $citation_sripper, $logger); try { $mailgateway->process($raw_mail); } catch (Exception $e) { $logger->error($e->getMessage()); } $logger->info("End email gateway");
public function info($message) { $this->backend_logger->log($message, Feedback::INFO); }