Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Add on onUserBeforeResetConfirm to com_users ResetModel::processResetConfirm #44599

Open
wants to merge 11 commits into
base: 5.3-dev
Choose a base branch
from
Open
4 changes: 3 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ steps:
- git rev-parse origin/$MINORVERSION-dev > transfer/$MINORVERSION.txt
- php build/build.php --remote=origin/$MINORVERSION-dev --exclude-gzip --disable-patch-packages
- mv build/tmp/packages/* transfer/
- php build/build.php --remote=origin/$MINORVERSION-dev --exclude-zip --exclude-gzip --exclude-bzip2 --debug-build
- mv build/tmp/packages/* transfer/

- name: upload
image: joomlaprojects/docker-images:packager
Expand Down Expand Up @@ -430,6 +432,6 @@ trigger:

---
kind: signature
hmac: 92bc9a500addecbc0d8ea987a668bee4abeae8bbab444e7105ce134ba3ffe96b
hmac: 10ae86041b814459e0a4618a7fa2356480177af7966412cc050e9902e9384cbe

...
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public function addLog($messages, $messageLanguageKey, $context, $userId = 0)
@trigger_error(\sprintf('User ID must be an integer in %s.', __METHOD__), E_USER_DEPRECATED);
}

$user = $userId ? $this->getUserFactory()->loadUserById($userId) : $this->getCurrentUser();
try {
$user = $userId ? $this->getUserFactory()->loadUserById($userId) : $this->getCurrentUser();
} catch (\UnexpectedValueException $e) {
@trigger_error(\sprintf('UserFactory must be set, this will not be caught anymore in 7.0.'), E_USER_DEPRECATED);
$user = Factory::getUser($userId);
}

$db = $this->getDatabase();
$date = Factory::getDate();
$params = ComponentHelper::getComponent('com_actionlogs')->getParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ protected function prepareTable($table)
// Set the values
$table->created = $date->toSql();
$table->created_by = $user->id;
$table->version = 1;

// Set ordering to the last item if not set
if (empty($table->ordering)) {
Expand All @@ -364,10 +365,8 @@ protected function prepareTable($table)
// Set the values
$table->modified = $date->toSql();
$table->modified_by = $user->id;
$table->version++;
}

// Increment the content version number.
$table->version++;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ protected function prepareTable($table)
if (empty($table->id)) {
// Set the values
$table->created = $date;
$table->version = 1;

// Set ordering to the last item if not set
if (empty($table->ordering)) {
Expand All @@ -379,10 +380,8 @@ protected function prepareTable($table)
// Set the values
$table->modified = $date;
$table->modified_by = $this->getCurrentUser()->id;
$table->version++;
}

// Increment the content version number.
$table->version++;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ protected function prepareTable($table)
}

// Increment the content version number.
$table->version++;
$table->version = empty($table->version) ? 1 : $table->version + 1;

// Reorder the articles within the category so the new article is first
if (empty($table->id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ protected function prepareTable($table)
if (empty($table->id)) {
// Set the values
$table->created = $date->toSql();
$table->version = 1;

// Set ordering to the last item if not set
if (empty($table->ordering)) {
Expand All @@ -321,10 +322,8 @@ protected function prepareTable($table)
// Set the values
$table->modified = $date->toSql();
$table->modified_by = $user->id;
$table->version++;
}

// Increment the content version number.
$table->version++;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function _getList($query, $limitstart = 0, $limit = 0)
$escapedSearchString = $this->refineSearchStringToRegex($search, '/');

foreach ($result as $i => $item) {
if (!preg_match("/$escapedSearchString/i", $item->name)) {
if (!preg_match("/$escapedSearchString/iu", $item->name)) {
unset($result[$i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_tags/src/Model/TagModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function save($data)
protected function prepareTable($table)
{
// Increment the content version number.
$table->version++;
$table->version = empty($table->version) ? 1 : $table->version + 1;
}

/**
Expand Down
110 changes: 66 additions & 44 deletions build/build.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function usage(string $command)
echo PHP_TAB . PHP_TAB . '--include-bzip2:' . PHP_TAB . PHP_TAB . 'Exclude the generation of .tar.bz2 packages' . PHP_EOL;
echo PHP_TAB . PHP_TAB . '--exclude-zstd:' . PHP_TAB . PHP_TAB . PHP_TAB . 'Include the generation of .tar.zst packages' . PHP_EOL;
echo PHP_TAB . PHP_TAB . '--disable-patch-packages:' . PHP_TAB . 'Disable the generation of patch packages' . PHP_EOL;
echo PHP_TAB . PHP_TAB . '--debug-build:' . PHP_TAB . 'Include development packages and build folder' . PHP_EOL;
echo PHP_TAB . PHP_TAB . '--help:' . PHP_TAB . PHP_TAB . PHP_TAB . PHP_TAB . 'Show this help output' . PHP_EOL;
echo PHP_EOL;
}
Expand Down Expand Up @@ -236,9 +237,10 @@ function clean_composer(string $dir)
$fullpath = $tmp . '/' . $time;

// Parse input options
$options = getopt('', ['help', 'remote::', 'exclude-zip', 'exclude-gzip', 'include-bzip2', 'exclude-zstd', 'disable-patch-packages']);
$options = getopt('', ['help', 'remote::', 'exclude-zip', 'exclude-gzip', 'include-bzip2', 'exclude-zstd', 'debug-build', 'disable-patch-packages']);

$remote = $options['remote'] ?? false;
$debugBuild = isset($options['debug-build']);
$excludeZip = isset($options['exclude-zip']);
$excludeGzip = isset($options['exclude-gzip']);
$excludeBzip2 = !isset($options['include-bzip2']);
Expand All @@ -265,6 +267,11 @@ function clean_composer(string $dir)
$includeExtraTextfiles = true;
}

$composerOptions = ' ';
if (!$debugBuild) {
$composerOptions .= '--no-dev';
}

echo "Start build for remote $remote.\n";
echo "Delete old release folder.\n";
system('rm -rf ' . $tmp);
Expand All @@ -277,7 +284,7 @@ function clean_composer(string $dir)
system('cp build/fido.jwt ' . $fullpath . '/plugins/system/webauthn/fido.jwt');
// Install PHP and NPM dependencies and compile required media assets, skip Composer autoloader until post-cleanup
chdir($fullpath);
system('composer install --no-dev --no-autoloader --ignore-platform-reqs', $composerReturnCode);
system('composer install --no-autoloader --ignore-platform-reqs' . $composerOptions, $composerReturnCode);

if ($composerReturnCode !== 0) {
echo "`composer install` did not complete as expected.\n";
Expand Down Expand Up @@ -318,16 +325,22 @@ function clean_composer(string $dir)
}

// Clean the checkout of extra resources
clean_checkout($fullpath);
if (!$debugBuild) {
clean_checkout($fullpath);
}

// Regenerate the Composer autoloader without deleted files
system('composer dump-autoload --no-dev --optimize --no-scripts');
system('composer dump-autoload --optimize --no-scripts' . $composerOptions);

// Clean the Composer manifests now
clean_composer($fullpath);
if (!$debugBuild) {
clean_composer($fullpath);
}

// And cleanup the Node installation
system('rm -rf node_modules');
if (!$debugBuild) {
system('rm -rf node_modules');
}

echo "Workspace built.\n";

Expand Down Expand Up @@ -449,11 +462,17 @@ function clean_composer(string $dir)
// For the packages, replace spaces in stability (RC) with underscores
$packageStability = str_replace(' ', '_', Version::DEV_STATUS);

if ($debugBuild) {
$packageStability .= '-Debug';
}

// Delete the files and folders we exclude from the packages (tests, docs, build, etc.).
echo "Delete folders not included in packages.\n";

foreach ($doNotPackage as $removeFile) {
system('rm -rf ' . $time . '/' . $removeFile);
if (!$debugBuild) {
foreach ($doNotPackage as $removeFile) {
system('rm -rf ' . $time . '/' . $removeFile);
}
}

// Count down starting with the latest release and add diff files to this array
Expand Down Expand Up @@ -498,7 +517,8 @@ function clean_composer(string $dir)
$dirtyHackForMediaCheck = \in_array('administrator/components/com_media/resources', $fullPath);
}

if ($dirtyHackForMediaCheck || $doNotPackageFile || $doNotPatchFile || $doNotPackageBaseFolder || $doNotPatchBaseFolder) {

if (!$debugBuild && ($dirtyHackForMediaCheck || $doNotPackageFile || $doNotPatchFile || $doNotPackageBaseFolder || $doNotPatchBaseFolder)) {
continue;
}

Expand Down Expand Up @@ -619,45 +639,47 @@ function clean_composer(string $dir)
}

// Create full update file without the default logs directory, installation folder, or sample images.
echo "Build full update package.\n";
system('rm -r administrator/logs');
system('rm -r installation');
system('rm -r images/banners');
system('rm -r images/headers');
system('rm -r images/sampledata');
system('rm images/joomla_black.png');
system('rm images/powered_by.png');
if (!$debugBuild) {
echo "Build full update package.\n";
system('rm -r administrator/logs');
system('rm -r installation');
system('rm -r images/banners');
system('rm -r images/headers');
system('rm -r images/sampledata');
system('rm images/joomla_black.png');
system('rm images/powered_by.png');

if (!$excludeZip) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.zip';
echo "Building " . $packageName . "... ";
system('zip -r ../packages/' . $packageName . ' * > /dev/null');
echo "done.\n";
$checksums[$packageName] = [];
}
if (!$excludeZip) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.zip';
echo "Building " . $packageName . "... ";
system('zip -r ../packages/' . $packageName . ' * > /dev/null');
echo "done.\n";
$checksums[$packageName] = [];
}

if (!$excludeGzip) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.tar.gz';
echo "Building " . $packageName . "... ";
system('tar --create --gzip --file ../packages/' . $packageName . ' * > /dev/null');
echo "done.\n";
$checksums[$packageName] = [];
}
if (!$excludeGzip) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.tar.gz';
echo "Building " . $packageName . "... ";
system('tar --create --gzip --file ../packages/' . $packageName . ' * > /dev/null');
echo "done.\n";
$checksums[$packageName] = [];
}

if (!$excludeBzip2) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.tar.bz2';
echo "Building " . $packageName . "... ";
system('tar --create --bzip2 --file ../packages/' . $packageName . ' * > /dev/null');
echo "done.\n";
$checksums[$packageName] = [];
}
if (!$excludeBzip2) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.tar.bz2';
echo "Building " . $packageName . "... ";
system('tar --create --bzip2 --file ../packages/' . $packageName . ' * > /dev/null');
echo "done.\n";
$checksums[$packageName] = [];
}

if (!$excludeZstd) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.tar.zst';
echo "Building " . $packageName . "... ";
system('tar "-I zstd --ultra -22" --create --file ../packages/' . $packageName . ' * > /dev/null');
echo "done.\n";
$checksums[$packageName] = [];
if (!$excludeZstd) {
$packageName = 'Joomla_' . $fullVersion . '-' . $packageStability . '-Update_Package.tar.zst';
echo "Building " . $packageName . "... ";
system('tar "-I zstd --ultra -22" --create --file ../packages/' . $packageName . ' * > /dev/null');
echo "done.\n";
$checksums[$packageName] = [];
}
}

chdir('..');
Expand Down
10 changes: 9 additions & 1 deletion components/com_tags/src/Service/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,15 @@ public function parse(&$segments)

while (\count($segments)) {
$id = array_shift($segments);
$ids[] = $this->fixSegment($id);
$slug = $this->fixSegment($id);

// We did not find the segment as a tag in the DB
if ($slug === $id) {
array_unshift($segments, $id);
break;
}

$ids[] = $slug;
}

if (\count($ids)) {
Expand Down
21 changes: 17 additions & 4 deletions components/com_users/src/Model/ResetModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\Log\Log;
use Joomla\CMS\Mail\MailTemplate;
use Joomla\CMS\MVC\Model\FormModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\User\User;
Expand Down Expand Up @@ -205,7 +206,7 @@ public function processResetComplete($data)
'subject' => $user,
]
);
$app->getDispatcher()->dispatch($event->getName(), $event);
$this->getDispatcher()->dispatch($event->getName(), $event);

// Check for a user and that the tokens match.
if (empty($user) || $user->activation !== $token) {
Expand Down Expand Up @@ -255,7 +256,7 @@ public function processResetComplete($data)
'subject' => $user,
]
);
$app->getDispatcher()->dispatch($event->getName(), $event);
$this->getDispatcher()->dispatch($event->getName(), $event);

return true;
}
Expand Down Expand Up @@ -299,6 +300,18 @@ public function processResetConfirm($data)
return false;
}

PluginHelper::importPlugin('authentication', null, true, $this->getDispatcher());

$event = AbstractEvent::create(
'onUserBeforeResetConfirm',
[
'subject' => $this,
'username' => $data['username']
]
);
$data['username'] = $this->getDispatcher()->dispatch($event->getName(), $event)
->getArgument('username', $data['username']);

// Find the user id for the given token.
$db = $this->getDatabase();
$query = $db->getQuery(true)
Expand Down Expand Up @@ -457,7 +470,7 @@ public function processResetRequest($data)
'subject' => $user,
]
);
$app->getDispatcher()->dispatch($event->getName(), $event);
$this->getDispatcher()->dispatch($event->getName(), $event);

// Save the user to the database.
if (!$user->save(true)) {
Expand Down Expand Up @@ -505,7 +518,7 @@ public function processResetRequest($data)
'subject' => $user,
]
);
$app->getDispatcher()->dispatch($event->getName(), $event);
$this->getDispatcher()->dispatch($event->getName(), $event);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"require": {
"php": "^8.1.0",
"joomla/application": "^3.0.2",
"joomla/application": "^3.0.3",
"joomla/archive": "^3.0.2",
"joomla/authentication": "^3.0.1",
"joomla/console": "^3.0.1",
Expand Down
Loading