Migration complete

This commit is contained in:
2026-06-23 19:24:37 +02:00
parent 0436a99a7c
commit 39adc2171c
25 changed files with 517 additions and 25 deletions

View File

@@ -0,0 +1,79 @@
<?php
namespace RomhackPlaza\Master\Api\Controller;
use RomhackPlaza\Master\Helper\Migration;
use XF\Api\Controller\AbstractController;
use XF\Api\ControllerPlugin\UserPlugin;
use XF\Entity\User;
use XF\Entity\UserAuth;
use XF\Mvc\ParameterBag;
use XF\Mvc\Reply\AbstractReply;
use XF\Repository\UserRepository;
class MigrateController extends AbstractController
{
protected function preDispatchController($action, ParameterBag $params)
{
$rhpz_enable_migration = \XF::options()->rhpz_enable_migration;
if( !$rhpz_enable_migration ){
$this->error("Migration not enabled");
}
}
public function actionPostUser(): AbstractReply
{
$input = $this->filter([
'username' => 'str',
'email' => 'str',
'profile[about]' => 'str',
'profile[website]' => 'str',
'register_date' => 'uint',
'user_group_id' => 'uint',
'xf_user_id' => 'uint',
'avatar_path' => 'str',
'banner_path' => 'str',
'source_real_password' => 'str',
'wp_password' => 'str',
'xf_scheme_class' => 'str',
'xf_password_data' => 'str',
]);
$this->assertAdminPermission('user');
$this->assertRequiredApiInput(['username','email','user_group_id']);
/** @var UserRepository $userRepository */
$userRepository = \XF::repository(UserRepository::class);
$user = $userRepository->setupBaseUser(null);
$userPlugin = $this->plugin(UserPlugin::class);
$userPlugin->userSaveProcessAdmin($user)->run();
/** @var UserAuth $authUser */
$authUser = $user->getExistingRelation('Auth');
if( $input['source_real_password'] === 'wp' ){
$authUser->scheme_class = 'RomhackPlaza\Master:WordPress';
$authUser->data = ['hash' => $input['wp_password']];
$authUser->save();
} elseif( $input['source_real_password'] === 'xf' ){
$authUser->scheme_class = $input['xf_scheme_class'];
$authUser->data = @unserialize($input['xf_password_data']);
$authUser->save();
}
if( $input['avatar_path'] !== "" ){
Migration::setAvatarFromPath($input['avatar_path'], $user);
}
if( $input['banner_path'] !== "" ){
Migration::setBannerFromPath($input['banner_path'], $user);
}
if( $input['register_date'] != 0 ){
$user->register_date = $input['register_date'];
$user->save();
}
return $this->apiSuccess(['success' => true, 'user_id' => $user->user_id, 'password_set' => true ]);
}
}