protected function afterDelete() { if (\GO::modules()->isInstalled('log')) { Log::create(Log::ACTION_DELETE, 'Removed ' . $this->contact->name . ' from addresslist ' . $this->addresslist->name, $this->className(), $this->contact_id . ':' . $this->addresslist_id); } return parent::afterDelete(); }
public function send(\Swift_Mime_Message $message, &$failedRecipients = null) { if (!empty(\GO::config()->disable_mail)) { throw new \Exception("E-mail sending is disabled!"); } if (\GO::config()->debug) { $getTo = $message->getTo(); if (!empty($getTo)) { $getTo = implode(",", array_keys($getTo)); } else { $getTo = ''; } \GO::debug("Sending e-mail to " . $getTo); } if (\GO::modules()->isInstalled("log")) { $str = ""; $from = $message->getFrom(); if (!empty($from)) { $str .= implode(",", array_keys($from)); } else { $str .= "unknown"; } $str .= " -> "; $to = $message->getTo(); if (!empty($to)) { $str .= implode(",", array_keys($to)); } $to = $message->getCc(); if (!empty($to)) { $str .= implode(",", array_keys($to)); } $to = $message->getBcc(); if (!empty($to)) { $str .= implode(",", array_keys($to)); } \GO\Log\Model\Log::create("email", $str); } // debug_print_backtrace(); // exit("NO MAIL"); //workaround https://github.com/swiftmailer/swiftmailer/issues/335 $messageId = $message->getId(); $count = parent::send($message, $failedRecipients); $message->setId($messageId); // Check if a tmp dir is created to store attachments. // If so, then remove the tmp dir if the mail is send successfully. $tmpDir = $message->getTmpDir(); if (!empty($tmpDir)) { $folder = new \GO\Base\Fs\Folder($tmpDir); // Check if folder is deleted successfully if ($folder->delete()) { \GO::debug('Clear attachments tmp directory: ' . $tmpDir); } else { \GO::debug('Failed to clear attachments tmp directory: ' . $tmpDir); } } return $count; }
protected function afterSave($wasNew) { if ($this->aclItem) { //Add log message for activitylog here if (\GO::modules()->isInstalled("log")) { \GO\Log\Model\Log::create("acl", $this->aclItem->description, $this->aclItem->className(), $this->aclItem->id); } $this->aclItem->touch(); } return parent::afterSave($wasNew); }
protected function actionRotate($params) { $this->requireCli(); $findParams = \GO\Base\Db\FindParams::newInstance(); $findParams->getCriteria()->addCondition('ctime', \GO\Base\Util\Date::date_add(time(), -\GO::config()->log_max_days), '<'); $stmt = \GO\Log\Model\Log::model()->find($findParams); $count = $stmt->rowCount(); echo "Dumping " . $count . " records to CSV file\n"; if ($count) { $logPath = '/var/log/groupoffice/' . \GO::config()->id . '.csv'; $csvLogFile = new \GO\Base\Fs\CsvFile($logPath); $csvLogFile->parent()->create(); while ($log = $stmt->fetch()) { if (!$csvLogFile->putRecord(array_values($log->getAttributes('formatted')))) { throw new \Exception("Could not write to CSV log file: " . $csvLogFile->path()); } $log->delete(); } } echo "Done\n"; }
protected function actionSwitch($params) { // // if(!\GO::user()->isAdmin()) // throw new \Exception("This feature is for admins only!"); $oldUsername = \GO::user()->username; $debug = !empty(\GO::session()->values['debug']); $user = \GO\Base\Model\User::model()->findByPk($params['user_id']); \GO::session()->values = array(); //clear session \GO::session()->setCurrentUser($user->id); //\GO::session()->setCompatibilitySessionVars(); if ($debug) { \GO::session()->values['debug'] = $debug; } \GO::infolog("ADMIN logged-in as user: \"" . $user->username . "\" from IP: " . $_SERVER['REMOTE_ADDR']); if (\GO::modules()->isInstalled('log')) { \GO\Log\Model\Log::create('switchuser', "'" . $oldUsername . "' logged in as '" . $user->username . "'"); } $this->redirect(); }
/** * Will all a log record in go_log * Made protected to be used in \GO\Files\Model\File * @param string $action * @param boolean $save set the false to not directly save the create Log record * @return boolean|\GO\Log\Model\Log returns the created log or succuss status when save is true */ protected function log($action, $save = true) { $message = $this->getLogMessage($action); if ($message && GO::modules()->isInstalled('log')) { $log = new \GO\Log\Model\Log(); $pk = $this->pk; $log->model_id = is_array($pk) ? var_export($pk, true) : $pk; $log->action = $action; $log->model = $this->className(); $log->message = $message; $log->object = $this; if ($save) { return $log->save(); } else { return $log; } } }
/** * Log a custom message * * @param string $action eg update, save * @param string $message */ public static function create($action, $message, $model_name = "", $model_id = 0) { $log = new Log(); $log->model_id = $model_id; $log->action = $action; $log->model = $model_name; $log->message = $message; $log->save(); }