PayPal Donation Extension

Create log with username - PayPal Donation Extension

Create log with username

by salvocortesiano » Sat Jun 08, 2024 10:05 am

Hi Skouat,
I finally updated to the latest version 3.3.12 :D I installed the extension and, it works very well.
I wanted to ask you: how can I modify this script so that when the log file of the user who donated is created "/store/ext/ppde/", it contains the username?
Egs. salvo_ppde_tx_1717688014_tlkz5g3upzm6l5pr.log

Code: Select all

$this->log_path_filename = $this->path_helper->get_phpbb_root_path() . 'store/ext/ppde/' . $this->user->data['username'] . '_ppde_tx_' . time() . '_' . unique_id() . '.log';

Code: Select all

public function __construct(
		config $config,
		filesystem_interface $filesystem,
		path_helper $path_helper,
		main_controller $ppde_controller_main,
	)
	{
		$this->config = $config;
		$this->filesystem = $filesystem;
		$this->path_helper = $path_helper;
		$this->ppde_controller_main = $ppde_controller_main;
		
		$this->log_path_filename = $this->path_helper->get_phpbb_root_path() . 'store/ext/ppde/ppde_tx_' . time() . '_' . unique_id() . '.log';
	}
Thanks in advance.
Best Regards
Salvo
P.S. Time has passed, and as you can see my English has not improved :lol:
The best way to predict the future is to invent it!
Image
User avatar
salvocortesiano
Registered User
Posts: 242
Joined: Mon Mar 22, 2010 1:49 pm
Location: Florence (Italy)
Name: Salvo Cortesiano

Re: Create log with username

by Skouat » Mon Jun 10, 2024 7:43 pm

Hi Salvo,
salvocortesiano wrote: I finally updated to the latest version 3.3.12 I installed the extension and, it works very well.
Glad to hear you finally did it.
salvocortesiano wrote: how can I modify this script so that when the log file of the user who donated is created "/store/ext/ppde/", it contains the username?
You need to declare the "user" objet before calling the object.

Take a look on the docs : https://area51.phpbb.com/docs/dev/3.3.x ... -injection
Just look the "$user" parts and references.

And here is an advice.
Use user->data['username_clean'] instead of user->data['username'], because username could contains invalid characters for naming files on the filesystem.

Best
salvocortesiano wrote: P.S. Time has passed, and as you can see my English has not improved
Same for me ;)
Skouat
Code Contributor
Posts: 1054
Joined: Mon Mar 10, 2008 5:30 pm
Location: France

Re: Create log with username

by salvocortesiano » Tue Jun 11, 2024 11:00 am

Skouat wrote:Hi Salvo,
salvocortesiano wrote: I finally updated to the latest version 3.3.12 I installed the extension and, it works very well.
Glad to hear you finally did it.
salvocortesiano wrote: how can I modify this script so that when the log file of the user who donated is created "/store/ext/ppde/", it contains the username?
You need to declare the "user" objet before calling the object.

Take a look on the docs : https://area51.phpbb.com/docs/dev/3.3.x ... -injection
Just look the "$user" parts and references.

And here is an advice.
Use user->data['username_clean'] instead of user->data['username'], because username could contains invalid characters for naming files on the filesystem.

Best
salvocortesiano wrote: P.S. Time has passed, and as you can see my English has not improved
Same for me ;)
Thanks Skouat,
I tried, but I used user->data['username'] and not user->data['username_clean'].
Thanks
Best Regards

Salvo
The best way to predict the future is to invent it!
Image
User avatar
salvocortesiano
Registered User
Posts: 242
Joined: Mon Mar 22, 2010 1:49 pm
Location: Florence (Italy)
Name: Salvo Cortesiano

Re: Create log with username

by salvocortesiano » Tue Jun 11, 2024 2:10 pm

Hi Skouat,
if I add '@user' to the services.yml file my forum goes into http error 500!
I saw that the 'controllers.yml' file contains the call to 'ipn_log.php' the file where I should make the change:

Code: Select all

    skouat.ppde.ipn_log:
        class: skouat\ppde\controller\ipn_log
        arguments:
            - '@config'
            - '@filesystem'
            - '@path_helper'
            - '@user'    <---------------------------------- adding
            - '@skouat.ppde.controller'

Code: Select all

use phpbb\config\config;
use phpbb\filesystem\filesystem_interface;
use phpbb\path_helper;

use phpbb\user; <---------------------------------- adding

class ipn_log
{
	protected $config;
	protected $filesystem;
	protected $path_helper;
	protected $ppde_controller_main;
	
	protected $user; <---------------------------------- adding
	
	/**
	 * @var string
	 */
	private $log_path_filename;
	/**
	 * The output handler. A null handler is configured by default.
	 *
	 * @var \skouat\ppde\output_handler\log_wrapper_output_handler
	 */
	private $output_handler;
	/**
	 * If true, the error are logged into /store/ppde_transactions.log.
	 * If false, error aren't logged. Default false.
	 *
	 * @var boolean
	 */
	private $use_log_error = false;

	/** @var array */
	private $report_data = ['remote_uri'             => '',
							'remote_type'            => '',
							'remote_report_response' => '',
							'remote_response_status' => '',
							'remote_data'            => [],
	];

	/**
	 * Constructor
	 *
	 * @param config               $config               Config object
	 * @param filesystem_interface $filesystem           phpBB's filesystem service
	 * @param path_helper          $path_helper          Path helper object
	 * @param main_controller      $ppde_controller_main Main controller
	 *
	 * @access public
	 */
	public function __construct(
		config $config,
		filesystem_interface $filesystem,
		path_helper $path_helper,
		main_controller $ppde_controller_main,
		
		user $user, <---------------------------------- adding
		
	)
	{
		$this->config = $config;
		$this->filesystem = $filesystem;
		$this->path_helper = $path_helper;
		$this->ppde_controller_main = $ppde_controller_main;
		
		$this->user = $user; <---------------------------------- adding
		
		$this->log_path_filename = $this->path_helper->get_phpbb_root_path() . 'store/ext/ppde/' . user->data['username_clean'] . ' _ppde_tx_' . time() . '_' . unique_id() . '.log';
	}
By making these changes the board does not give an error, but when I go to the Extensions TAB, and click on 'PayPal IPN Features' or 'Paypal Overview' return the error http 500. Any suggestions? Do I need to make changes to other configuration files?

Best Regards
Salvo :)
The best way to predict the future is to invent it!
Image
User avatar
salvocortesiano
Registered User
Posts: 242
Joined: Mon Mar 22, 2010 1:49 pm
Location: Florence (Italy)
Name: Salvo Cortesiano

Re: Create log with username

by Skouat » Tue Jun 11, 2024 5:33 pm

  • In the conroller.yml, the order needs to reflect the order you use in the "constructor"

    Replace

    Code: Select all

                - '@user'
                - '@skouat.ppde.controller'
    with

    Code: Select all

                - '@skouat.ppde.controller'
                - '@user'
  • In the constructor, remove the trailing coma
    replace user $user, with user $user
  • replace user->data['username_clean'] with $this->user->data['username_clean'].
  • purge the cache.
Skouat
Code Contributor
Posts: 1054
Joined: Mon Mar 10, 2008 5:30 pm
Location: France

Re: Create log with username

by salvocortesiano » Tue Jun 11, 2024 6:53 pm

Skouat wrote:
  • In the conroller.yml, the order needs to reflect the order you use in the "constructor"

    Replace

    Code: Select all

                - '@user'
                - '@skouat.ppde.controller'
    with

    Code: Select all

                - '@skouat.ppde.controller'
                - '@user'
  • In the constructor, remove the trailing coma
    replace user $user, with user $user
  • replace user->data['username_clean'] with $this->user->data['username_clean'].
  • purge the cache.
Thank You very much. I'll try this change tomorrow and let you know :D
Regards
Salvo
The best way to predict the future is to invent it!
Image
User avatar
salvocortesiano
Registered User
Posts: 242
Joined: Mon Mar 22, 2010 1:49 pm
Location: Florence (Italy)
Name: Salvo Cortesiano

Re: Create log with username

by salvocortesiano » Thu Jun 13, 2024 8:50 am

Good morning Skouat,
I made the necessary changes as you recommended, but unfortunately once the donation is made, it creates a log file not with the username but anonymous_ecc...
ppde_anon.jpg
Any suggestions? I attach the part of code:

/config/controllers.yml

Code: Select all

skouat.ppde.ipn_log:
        class: skouat\ppde\controller\ipn_log
        arguments:
            - '@config'
            - '@filesystem'
            - '@path_helper'
            - '@skouat.ppde.controller'
            - '@user'   <-------------------------------------------------- adding
/controller/ipn_log.php

Code: Select all

use phpbb\config\config;
use phpbb\filesystem\filesystem_interface;
use phpbb\path_helper;
use phpbb\user;    <-------------------------------------------------- adding

class ipn_log
{
	protected $config;
	protected $filesystem;
	protected $path_helper;
	protected $ppde_controller_main;
	protected $user;   <-------------------------------------------------- adding
	
	/**
	 * @var string
	 */
	private $log_path_filename;
	/**
	 * The output handler. A null handler is configured by default.
	 *
	 * @var \skouat\ppde\output_handler\log_wrapper_output_handler
	 */
	private $output_handler;
	/**
	 * If true, the error are logged into /store/ppde_transactions.log.
	 * If false, error aren't logged. Default false.
	 *
	 * @var boolean
	 */
	private $use_log_error = false;

	/** @var array */
	private $report_data = ['remote_uri'             => '',
							'remote_type'            => '',
							'remote_report_response' => '',
							'remote_response_status' => '',
							'remote_data'            => [],
	];

	/**
	 * Constructor
	 *
	 * @param config               $config               Config object
	 * @param filesystem_interface $filesystem           phpBB's filesystem service
	 * @param path_helper          $path_helper          Path helper object
	 * @param main_controller      $ppde_controller_main Main controller
	 *
	 * @access public
	 */
	public function __construct(
		config $config,
		filesystem_interface $filesystem,
		path_helper $path_helper,
		main_controller $ppde_controller_main,
		user $user   <-------------------------------------------------- adding
	)
	{
		$this->config = $config;
		$this->filesystem = $filesystem;
		$this->path_helper = $path_helper;
		$this->ppde_controller_main = $ppde_controller_main;
		$this->user = $user;   <-------------------------------------------------- adding
		
		$this->log_path_filename = $this->path_helper->get_phpbb_root_path() . 'store/ext/ppde/' . $this->user->data['username_clean'] . '_ppde_tx_' . time() . '_' . unique_id() . '.log';   <-------------------------------------------------- adding
	}
Thanks
Best Regards... Salvo
The best way to predict the future is to invent it!
Image
User avatar
salvocortesiano
Registered User
Posts: 242
Joined: Mon Mar 22, 2010 1:49 pm
Location: Florence (Italy)
Name: Salvo Cortesiano

Re: Create log with username

by Skouat » Thu Jun 13, 2024 10:44 pm

salvocortesiano wrote: it creates a log file not with the username but anonymous
Of course, this makes sense, because in reality it isn't the user who access to the ipn_log function, but PayPal's API.
This kind of change will be more complicated and involve more modifications to the code. I will not work on this.

But if you provide code changes and face an error, I may consider helping you.
Skouat
Code Contributor
Posts: 1054
Joined: Mon Mar 10, 2008 5:30 pm
Location: France

Re: Create log with username

by salvocortesiano » Fri Jun 14, 2024 6:59 am

Skouat wrote:
salvocortesiano wrote: it creates a log file not with the username but anonymous
Of course, this makes sense, because in reality it isn't the user who access to the ipn_log function, but PayPal's API.
This kind of change will be more complicated and involve more modifications to the code. I will not work on this.
I figured, I'll work on it and hopefully we can do it :)
Skouat wrote:
salvocortesiano wrote:But if you provide code changes and face an error, I may consider helping you.
If I need a little help, then I'll ask you. Thanks for your time :D

Regards
Salvo
The best way to predict the future is to invent it!
Image
User avatar
salvocortesiano
Registered User
Posts: 242
Joined: Mon Mar 22, 2010 1:49 pm
Location: Florence (Italy)
Name: Salvo Cortesiano