80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?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 ]);
|
|
|
|
}
|
|
}
|