phpbb\log\log::add PHP Method

add() public method

{@inheritDoc}
public add ( $mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = [] )
    public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array())
    {
        if (!$this->is_enabled($mode)) {
            return false;
        }
        if ($log_time === false) {
            $log_time = time();
        }
        $sql_ary = array('user_id' => $user_id ? (int) $user_id : ANONYMOUS, 'log_ip' => empty($log_ip) ? '' : $log_ip, 'log_time' => $log_time, 'log_operation' => $log_operation);
        switch ($mode) {
            case 'admin':
                $sql_ary += array('log_type' => LOG_ADMIN, 'log_data' => !empty($additional_data) ? serialize($additional_data) : '');
                break;
            case 'mod':
                $forum_id = isset($additional_data['forum_id']) ? (int) $additional_data['forum_id'] : 0;
                unset($additional_data['forum_id']);
                $topic_id = isset($additional_data['topic_id']) ? (int) $additional_data['topic_id'] : 0;
                unset($additional_data['topic_id']);
                $sql_ary += array('log_type' => LOG_MOD, 'forum_id' => $forum_id, 'topic_id' => $topic_id, 'log_data' => !empty($additional_data) ? serialize($additional_data) : '');
                break;
            case 'user':
                $reportee_id = (int) $additional_data['reportee_id'];
                unset($additional_data['reportee_id']);
                $sql_ary += array('log_type' => LOG_USERS, 'reportee_id' => $reportee_id, 'log_data' => !empty($additional_data) ? serialize($additional_data) : '');
                break;
            case 'critical':
                $sql_ary += array('log_type' => LOG_CRITICAL, 'log_data' => !empty($additional_data) ? serialize($additional_data) : '');
                break;
        }
        /**
         * Allows to modify log data before we add it to the database
         *
         * NOTE: if sql_ary does not contain a log_type value, the entry will
         * not be stored in the database. So ensure to set it, if needed.
         *
         * @event core.add_log
         * @var	string	mode			Mode of the entry we log
         * @var	int		user_id			ID of the user who triggered the log
         * @var	string	log_ip			IP of the user who triggered the log
         * @var	string	log_operation	Language key of the log operation
         * @var	int		log_time		Timestamp, when the log was added
         * @var	array	additional_data	Array with additional log data
         * @var	array	sql_ary			Array with log data we insert into the
         *							database. If sql_ary[log_type] is not set,
         *							we won't add the entry to the database.
         * @since 3.1.0-a1
         */
        $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary');
        extract($this->dispatcher->trigger_event('core.add_log', compact($vars)));
        // We didn't find a log_type, so we don't save it in the database.
        if (!isset($sql_ary['log_type'])) {
            return false;
        }
        $this->db->sql_query('INSERT INTO ' . $this->log_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary));
        return $this->db->sql_nextid();
    }

Usage Example

Exemplo n.º 1
0
	protected function execute(InputInterface $input, OutputInterface $output)
	{
		$this->migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($this->user, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem));

		$this->migrator->create_migrations_table();

		$this->cache->purge();

		$this->load_migrations();
		$orig_version = $this->config['version'];
		while (!$this->migrator->finished())
		{
			try
			{
				$this->migrator->update();
			}
			catch (\phpbb\db\migration\exception $e)
			{
				$output->writeln('<error>' . $e->getLocalisedMessage($this->user) . '</error>');
				$this->finalise_update();
				return 1;
			}
		}

		if ($orig_version != $this->config['version'])
		{
			$this->log->add('admin', ANONYMOUS, '', 'LOG_UPDATE_DATABASE', time(), array($orig_version, $this->config['version']));
		}

		$this->finalise_update();
		$output->writeln($this->user->lang['DATABASE_UPDATE_COMPLETE']);
	}
All Usage Examples Of phpbb\log\log::add