Advertisement

Strange Deprecated Issue Topic is solved

For Joomla! 5.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
neo314
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Sat Mar 13, 2010 4:22 am

Strange Deprecated Issue

Post by neo314 » Fri Jan 17, 2025 7:44 am

Does anyone have any idea why I am getting this deprecated error on my provider.php file when the exact same code does not seem to do it in other provider.php files?

Code: Select all

Notice: Only variables should be passed by reference in C:\BLAZING\_WEB\ocffire.org\public_html\plugins\user\crewlist\services\provider.php on line 37

Code: Select all

public function register(Container $container): void
    {
        $container->set(
            PluginInterface::class,
            function (Container $container) {
                $plugin     = new Crewlist(
 LINE 37 -->                   [b][i]$container->get(DispatcherInterface::class),[/i][/b]
                    (array) PluginHelper::getPlugin('user', 'crewlist')
                );
                $plugin->setApplication(Factory::getApplication());

                return $plugin;
            }
        );
    }
Last edited by toivo on Fri Jan 17, 2025 9:16 am, edited 1 time in total.
Reason: mod note: typo in subject

Advertisement
SharkyKZ
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3160
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Strange Depricated Issue

Post by SharkyKZ » Fri Jan 17, 2025 7:47 am

Check the constructor in Crewlist class. It probably expects the argument to be passed by reference:

Code: Select all

public function __construct(DispatcherInterface &$dispatcher, array $config = [])

neo314
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Sat Mar 13, 2010 4:22 am

Re: Strange Deprecated Issue

Post by neo314 » Fri Jan 17, 2025 6:07 pm

Thanks. That didn't help. I notice it is not in other plugins. Here is the full error report.

Notice: Only variables should be passed by reference in C:\BLAZING\_WEB\ocffire.org\public_html\plugins\user\crewlist\services\provider.php on line 37
Call Stack
# Time Memory Function Location
1 0.0110 402768 {main}( ) ...\index.php:0
2 0.0169 414168 require_once( 'C:\BLAZING\_WEB\ocffire.org\public_html\administrator\includes\app.php ) ...\index.php:32
3 0.1001 7645616 Joomla\CMS\Application\CMSApplication->execute( ) ...\app.php:58
4 0.1017 7832632 Joomla\CMS\Application\AdministratorApplication->doExecute( ) ...\CMSApplication.php:306
5 0.2396 15281368 Joomla\CMS\Application\AdministratorApplication->dispatch( $component = ??? ) ...\AdministratorApplication.php:205
6 0.2544 16417936 Joomla\CMS\Component\ComponentHelper::renderComponent( $option = 'com_users', $params = ??? ) ...\AdministratorApplication.php:150
7 0.2584 16668464 Joomla\CMS\Dispatcher\ComponentDispatcher->dispatch( ) ...\ComponentHelper.php:361
8 0.2600 16876192 Joomla\CMS\MVC\Controller\BaseController->execute( $task = 'display' ) ...\ComponentDispatcher.php:143
9 0.2600 16876192 Joomla\Component\Users\Administrator\Controller\DisplayController->display( $cachable = ???, $urlparams = ??? ) ...\BaseController.php:730
10 0.2612 16912000 Joomla\CMS\MVC\Controller\BaseController->display( $cachable = FALSE, $urlparams = [] ) ...\DisplayController.php:138
11 0.2659 17193816 Joomla\Component\Users\Administrator\View\User\HtmlView->display( $tpl = ??? ) ...\BaseController.php:697
12 0.2688 17202504 Joomla\CMS\MVC\View\AbstractView->get( $property = 'Form', $default = ??? ) ...\HtmlView.php:108
13 0.2688 17202536 Joomla\Component\Users\Administrator\Model\UserModel->getForm( $data = ???, $loadData = ??? ) ...\AbstractView.php:159
14 0.2688 17202912 Joomla\CMS\MVC\Model\FormModel->loadForm( $name = 'com_users.user', $source = 'user', $options = ['control' => 'jform', 'load_data' => TRUE], $clear = ???, $xpath = ??? ) ...\UserModel.php:129
15 0.2734 18156936 Joomla\Component\Users\Administrator\Model\UserModel->loadFormData( ) ...\FormBehaviorTrait.php:108
[ redacted ]
Last edited by toivo on Fri Jan 17, 2025 8:43 pm, edited 1 time in total.
Reason: mod note: disabled smilies in post Options for readability, truncated PHP call stack containing credentials

SharkyKZ
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3160
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Strange Deprecated Issue

Post by SharkyKZ » Fri Jan 17, 2025 7:01 pm

Post the code of Crewlist.php, not your passwords and personal info.

neo314
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Sat Mar 13, 2010 4:22 am

Re: Strange Deprecated Issue

Post by neo314 » Fri Jan 17, 2025 8:41 pm

SharkyKZ wrote: Fri Jan 17, 2025 7:01 pm Post the code of Crewlist.php, not your passwords and personal info.
crewlist.php

Code: Select all

<?php
namespace Blazingimages\Plugin\User\Crewlist\Extension;

// No direct access to this file
defined('_JEXEC') or die;

// Import the Joomla plugin library
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseFactory;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;

class Crewlist extends CMSPlugin
{
    // Constructor
    public function __construct(&$subject, $config = array())
    {
        parent::__construct($subject, $config);
    }

    /**
     * Event that is triggered when a user is created, updated or deleted.
     *
     * @param   array  $context  The context of the event (user.created, user.updated, user.deleted).
     * @param   object  $user    The user object.
     *
     * @return void
     */
    public function onUserAfterSave($user, $isNew, $success, $msg)
    {
        // Ensure this function only runs if the user has been saved successfully.
        if (!$success) {
            return;
        }

        // Load plugin parameters
        $crewlistDbName = $this->params->get('crewlistDbName');
        $crewlistDbUser = $this->params->get('crewlistDbUser');
        $crewlistDbPassword = $this->params->get('crewlistDbPassword');
        $crewlistDBTable = $this->params->get('crewlistDBTable');
        $crewlistAddress = $this->params->get('crewlistAddress');
        $crewlistDomain = $this->params->get('crewlistDomain');

        // Step 1: Create the comma separated list of emails
        $tempCrewlist = $this->getCrewlistEmails();

        // Step 2: Connect to the external database
        $options = array(
            'driver'   => 'mysqli',
            'host'     => 'localhost',
            'user'     => $crewlistDbUser,
            'password' => $crewlistDbPassword,
            'database' => $crewlistDbName
        );
        $dbFactory = new DatabaseFactory();
        $db = $dbFactory->getDriver('mysqli',$options);
        $db->connect();

        // Step 3: Check if a record with the crewlistAddress already exists
        $query = $db->getQuery(true)
            ->select('*')
            ->from($db->quoteName($crewlistDBTable))
            ->where($db->quoteName('address') . ' = ' . $db->quote($crewlistAddress));

        $db->setQuery($query);
        $existingRecord = $db->loadObject();

        // Step 4: Update or Insert the record as needed
        if ($existingRecord) {
            // Update existing record
            $query = $db->getQuery(true)
                ->update($db->quoteName($crewlistDBTable))
                ->set([
                    $db->quoteName('goto') . ' = ' . $db->quote($tempCrewlist),
                    $db->quoteName('domain') . ' = ' . $db->quote($crewlistDomain),
                    $db->quoteName('active') . ' = 1'
                ])
                ->where($db->quoteName('address') . ' = ' . $db->quote($crewlistAddress));

            $db->setQuery($query);
            $db->execute();
        } else {
            // Insert new record
            $query = $db->getQuery(true)
                ->insert($db->quoteName($crewlistDBTable))
                ->columns([
                    $db->quoteName('address'),
                    $db->quoteName('goto'),
                    $db->quoteName('domain'),
                    $db->quoteName('active')
                ])
                ->values(implode(',', [
                    $db->quote($crewlistAddress),
                    $db->quote($tempCrewlist),
                    $db->quote($crewlistDomain),
                    1
                ]));

            $db->setQuery($query);
            $db->execute();
        }
    }

    /**
     * Function to retrieve the comma separated list of emails where the custom field 'crewlist' equals 1
     *
     * @return string
     */
    private function getCrewlistEmails()
    {
        $db = Factory::getContainer()->get(DatabaseInterface::class);
        $db->connect();
		$query = $db->getQuery(true)
			->select($db->quoteName('uf.id'))
			->from($db->quoteName('#__fields','uf'))
			->where($db->quoteName('uf.context') . " = 'com_users.user' AND " . $db->quoteName('uf.name') . " = 'crewlist'");
        $query->string = $query->__toString();
        $db->setQuery($query);
        $field_id = $db->loadResult();
        if (!$field_id) {
            $app = Factory::getApplication();
            $app->enqueueMessage('The field "crewlist" does not exist. Please create it in user custom fields. The email list has not been updated', 'error');
            return false;
        } else {
            $query = $db->getQuery(true)
                ->select('u.email')
                ->from('#__users AS u')
                ->join('LEFT', '#__fields_values AS ufv ON u.id = ufv.item_id AND ufv.field_id = :fieldID')
                ->bind(':fieldID',$field_id,ParameterType::INTEGER)
                ->where($db->quoteName('ufv.value') . ' = 1');
            $query->string = $query->__toString();
            $db->setQuery($query);
            $emails = $db->loadColumn();
            return implode(',', $emails);
        }
    }
}
provider.php

Code: Select all

<?php

/**
 * @package     Joomla.Plugin
 * @subpackage  User.Crewlist
 *
 * @copyright   (C) 2023 Open Source Matters, Inc.
 * @license     GNU General Public License version 2 or later;
 */

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Blazingimages\Plugin\User\Crewlist\Extension\Crewlist;

return new class () implements ServiceProviderInterface {
    /**
     * Registers the service provider with a DI container.
     *
     * @param   Container  $container  The DI container.
     *
     * @return  void
     *
     * @since   4.4.0
     */
    public function register(Container $container): void
    {
        $container->set(
            PluginInterface::class,
            function (Container $container) {
                $plugin     = new Crewlist(
                    $container->get(DispatcherInterface::class),
                    (array) PluginHelper::getPlugin('user', 'crewlist')
                );
                $plugin->setApplication(Factory::getApplication());

                return $plugin;
            }
        );
    }
};

SharkyKZ
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3160
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Strange Deprecated Issue

Post by SharkyKZ » Fri Jan 17, 2025 9:01 pm

Remove the ampersand here:

Code: Select all

public function __construct(&$subject, $config = array())

neo314
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Sat Mar 13, 2010 4:22 am

Re: Strange Deprecated Issue

Post by neo314 » Fri Jan 17, 2025 9:10 pm

That did it. Thanks! Damn AI. I used AI to get started and I had to correct a lot of things but didn't even notice that. By reference...Duh...

Advertisement

Post Reply

Return to “Joomla! 5.x Coding”