XF 2.1 How to extend protected $updates

Robert9

Well-known member
Here

Code:
namespace XF\Service\User;

use XF\Entity\User;

class ContentChange extends \XF\Service\AbstractService
{
protected $updates = [
		'xf_admin_log' => ['user_id', 'emptyable' => false],
...

i need to add another var like

Code:
		'xf_user_lala' => [
			['user_id', 'emptyable' => false],
			['lala_user_id', 'emptyable' => false]
		],

So i have extended the class, but i dont know how extend $updates
 
You don't need to extend the class to extend that.

You need to create a "Code event listener" and listen to the user_content_change_init event.
 
Thank you. I found code in the xfmg

Code:
  <listener event_id="user_content_change_init" execute_order="10" callback_class="...\Listener" callback_method="userContentChangeInit" active="1" description="Register the updates that need to happen when a user is renamed, deleted, etc."/>


Code:
class Listener
{
	public static function userContentChangeInit(\XF\Service\User\ContentChange $changeService, array &$updates)
	{
		$updates['xf_lala'] = [
			['user_id', 'emptyable' => false],
			['lala_id', 'emptyable' => false]
		];
	}
 
Last edited:
Now i stuck here
Code:
namespace XF\Service\User;

use XF\Entity\User;

class Merge extends \XF\Service\AbstractService
...
Code:
	protected function postMergeCleanUp()
	{
		/** @var \XF\Repository\Trophy $trophyRepo */
		$trophyRepo = $this->repository('XF:Trophy');
		$trophyRepo->recalculateUserTrophyPoints($this->target);

		// anything left over is where both users were in the same conversation so we can remove the old records
		$this->db()->delete('xf_conversation_recipient', 'user_id = ?', $this->source->user_id);

		// prevent situations where a user can be following/ignoring themselves
		$this->db()->delete(
			'xf_user_follow',
			'user_id = ? AND (follow_user_id = ? OR follow_user_id = ?)',
			[$this->target->user_id, $this->target->user_id, $this->source->user_id]
		);
		$this->db()->delete(
			'xf_user_ignored',
			'user_id = ? AND (ignored_user_id = ? OR ignored_user_id = ?)',
			[$this->target->user_id, $this->target->user_id, $this->source->user_id]
		);

		$this->repository('XF:UserFollow')->rebuildFollowingCache($this->target->user_id);
		$this->repository('XF:UserIgnored')->rebuildIgnoredCache($this->target->user_id);
	}

I need to add:
Code:
		$this->db()->delete(
			'xf_lala',
			'user_id = ? AND (lala_id = ? OR lala_id = ?)',
			[$this->target->user_id, $this->target->user_id, $this->source->user_id]
		);
[/code

and

[code]		$this->repository('XF:UserLala')->rebuildLalaCache($this->target->user_id);

Here i extend the class or use also the listener?
 
Top Bottom