mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-24 00:57:17 +01:00
* [MOD] Installer refactoring.
This commit is contained in:
@@ -26,8 +26,8 @@ namespace SP\Modules\Web\Controllers;
|
||||
|
||||
use Klein\Klein;
|
||||
use SP\Bootstrap;
|
||||
use SP\Core\Install\Installer;
|
||||
use SP\Mvc\View\Template;
|
||||
use SP\Services\Install\Installer;
|
||||
use SP\Util\Util;
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,12 +30,12 @@ use SP\Core\Acl\ActionsInterface;
|
||||
use SP\Core\Crypt\CryptPKI;
|
||||
use SP\Core\Dic\ContainerException;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Core\Install\Installer;
|
||||
use SP\Core\Language;
|
||||
use SP\Core\Plugin\PluginUtil;
|
||||
use SP\Core\UI\Theme;
|
||||
use SP\Core\UI\ThemeInterface;
|
||||
use SP\Html\DataGrid\DataGridAction;
|
||||
use SP\Services\Install\Installer;
|
||||
use SP\Util\Checks;
|
||||
use SP\Util\Util;
|
||||
|
||||
|
||||
@@ -27,14 +27,14 @@ namespace SP\Modules\Web\Controllers;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Core\Install\Installer;
|
||||
use SP\Core\Language;
|
||||
use SP\DataModel\InstallData;
|
||||
use SP\Http\JsonResponse;
|
||||
use SP\Http\Request;
|
||||
use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
|
||||
use SP\Modules\Web\Controllers\Traits\JsonTrait;
|
||||
use SP\Mvc\View\Components\SelectItemAdapter;
|
||||
use SP\Services\Install\InstallData;
|
||||
use SP\Services\Install\Installer;
|
||||
use SP\Util\Checks;
|
||||
|
||||
/**
|
||||
@@ -118,7 +118,7 @@ class InstallController extends ControllerBase
|
||||
$installData->setHostingMode(Request::analyzeBool('hostingmode', false));
|
||||
|
||||
try {
|
||||
Installer::run($installData);
|
||||
$this->dic->get(Installer::class)->run($installData);
|
||||
|
||||
$this->returnJsonResponse(JsonResponse::JSON_SUCCESS_STICKY, __u('Instalación finalizada'));
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<td class="valField">
|
||||
<div class="lowres-title"><?php echo __('Versión sysPass'); ?></div>
|
||||
|
||||
<?php printf('%s (%s)', \SP\Core\Install\Installer::VERSION_TEXT, \SP\Html\Html::strongText(\SP\Util\Util::getVersionStringNormalized())); ?>
|
||||
<?php printf('%s (%s)', \SP\Services\Install\Installer::VERSION_TEXT, \SP\Html\Html::strongText(\SP\Util\Util::getVersionStringNormalized())); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $InstallData \SP\DataModel\InstallData
|
||||
* @var $this \SP\Mvc\View\Template
|
||||
* @var \SP\Mvc\View\Template $this
|
||||
*/
|
||||
?>
|
||||
<div id="actions" class="installer" align="center">
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Core\Install;
|
||||
namespace SP\Services\Install;
|
||||
|
||||
/**
|
||||
* Interface DatabaseInterface
|
||||
*
|
||||
* @package SP\Core\Install
|
||||
* @package SP\Services\Install
|
||||
*/
|
||||
interface DatabaseSetupInterface
|
||||
{
|
||||
@@ -22,7 +22,7 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\DataModel;
|
||||
namespace SP\Services\Install;
|
||||
|
||||
/**
|
||||
* Class InstallData
|
||||
@@ -3,8 +3,8 @@
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
@@ -23,20 +23,19 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Core\Install;
|
||||
namespace SP\Services\Install;
|
||||
|
||||
use SP\Config\Config;
|
||||
use SP\Config\ConfigData;
|
||||
use SP\Core\Crypt\Hash;
|
||||
use SP\Core\Dic;
|
||||
use SP\Core\Exceptions\InvalidArgumentException;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\DataModel\InstallData;
|
||||
use SP\DataModel\ProfileData;
|
||||
use SP\DataModel\UserData;
|
||||
use SP\DataModel\UserGroupData;
|
||||
use SP\DataModel\UserProfileData;
|
||||
use SP\Services\Config\ConfigService;
|
||||
use SP\Services\Service;
|
||||
use SP\Services\User\UserService;
|
||||
use SP\Services\UserGroup\UserGroupService;
|
||||
use SP\Services\UserProfile\UserProfileService;
|
||||
@@ -48,7 +47,7 @@ defined('APP_ROOT') || die();
|
||||
/**
|
||||
* Esta clase es la encargada de instalar sysPass.
|
||||
*/
|
||||
class Installer
|
||||
class Installer extends Service
|
||||
{
|
||||
use Dic\InjectableTrait;
|
||||
|
||||
@@ -59,34 +58,14 @@ class Installer
|
||||
const VERSION_TEXT = '3.0-dev';
|
||||
const BUILD = 18031401;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
/**
|
||||
* @var ConfigService
|
||||
*/
|
||||
protected $configService;
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
protected $userService;
|
||||
/**
|
||||
* @var UserGroupService
|
||||
*/
|
||||
protected $userGroupService;
|
||||
/**
|
||||
* @var UserProfileService
|
||||
*/
|
||||
protected $userProfileService;
|
||||
/**
|
||||
* @var DatabaseSetupInterface
|
||||
*/
|
||||
protected $dbs;
|
||||
/**
|
||||
* @var DatabaseConnectionData $databaseConnectionData
|
||||
*/
|
||||
protected $databaseConnectionData;
|
||||
/**
|
||||
* @var InstallData
|
||||
*/
|
||||
@@ -96,19 +75,6 @@ class Installer
|
||||
*/
|
||||
private $configData;
|
||||
|
||||
/**
|
||||
* Installer constructor.
|
||||
*
|
||||
* @param InstallData $installData
|
||||
* @throws Dic\ContainerException
|
||||
*/
|
||||
public function __construct(InstallData $installData)
|
||||
{
|
||||
$this->injectDependencies();
|
||||
|
||||
$this->installData = $installData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InstallData $installData
|
||||
* @return static
|
||||
@@ -119,19 +85,20 @@ class Installer
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public static function run(InstallData $installData)
|
||||
public function run(InstallData $installData)
|
||||
{
|
||||
$installer = new static($installData);
|
||||
$installer->checkData();
|
||||
$installer->install();
|
||||
$this->installData = $installData;
|
||||
|
||||
return $installer;
|
||||
$this->checkData();
|
||||
$this->install();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function checkData()
|
||||
private function checkData()
|
||||
{
|
||||
if (!$this->installData->getAdminLogin()) {
|
||||
throw new InvalidArgumentException(
|
||||
@@ -208,7 +175,7 @@ class Installer
|
||||
* @throws \SP\Core\Exceptions\ConstraintException
|
||||
* @throws \SP\Core\Exceptions\QueryException
|
||||
*/
|
||||
public function install()
|
||||
private function install()
|
||||
{
|
||||
$this->setupDbHost();
|
||||
$this->setupConfig();
|
||||
@@ -272,13 +239,16 @@ class Installer
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Dic\ContainerException
|
||||
* @param string $type
|
||||
* @throws SPException
|
||||
* @todo Select DB type
|
||||
*/
|
||||
private function setupDb()
|
||||
private function setupDb($type = 'mysql')
|
||||
{
|
||||
$this->dbs = new MySQL($this->installData);
|
||||
switch ($type) {
|
||||
case 'mysql':
|
||||
$this->dbs = new MySQL($this->installData, $this->configData);
|
||||
break;
|
||||
}
|
||||
|
||||
// Si no es modo hosting se crea un hash para la clave y un usuario con prefijo "sp_" para la DB
|
||||
if ($this->installData->isHostingMode()) {
|
||||
@@ -300,7 +270,7 @@ class Installer
|
||||
private function setupDBConnectionData()
|
||||
{
|
||||
// FIXME: ugly!!
|
||||
$this->databaseConnectionData->refreshFromConfig($this->configData);
|
||||
$this->dic->get(DatabaseConnectionData::class)->refreshFromConfig($this->configData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,15 +315,19 @@ class Installer
|
||||
$userProfileData->setName('Admin');
|
||||
$userProfileData->setProfile(new ProfileData());
|
||||
|
||||
$userService = $this->dic->get(UserService::class);
|
||||
$userGroupService = $this->dic->get(UserGroupService::class);
|
||||
$userProfileService = $this->dic->get(UserProfileService::class);
|
||||
|
||||
// Datos del usuario
|
||||
$userData = new UserData();
|
||||
$userData->setUserGroupId($this->userGroupService->create($userGroupData));
|
||||
$userData->setUserProfileId($this->userProfileService->create($userProfileData));
|
||||
$userData->setUserGroupId($userGroupService->create($userGroupData));
|
||||
$userData->setUserProfileId($userProfileService->create($userProfileData));
|
||||
$userData->setLogin($this->installData->getAdminLogin());
|
||||
$userData->setName('sysPass Admin');
|
||||
$userData->setIsAdminApp(1);
|
||||
|
||||
$this->userService->createWithMasterPass($userData, $this->installData->getAdminPass(), $this->installData->getMasterPassword());
|
||||
$userService->createWithMasterPass($userData, $this->installData->getAdminPass(), $this->installData->getMasterPassword());
|
||||
|
||||
// __u('Error al actualizar la clave maestra del usuario "admin"'),
|
||||
} catch (\Exception $e) {
|
||||
@@ -370,26 +344,11 @@ class Installer
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
* @param ConfigService $configService
|
||||
* @param UserService $userService
|
||||
* @param UserGroupService $userGroupService
|
||||
* @param UserProfileService $userProfileService
|
||||
* @param DatabaseConnectionData $databaseConnectionData
|
||||
* initialize
|
||||
*/
|
||||
public function inject(Config $config,
|
||||
ConfigService $configService,
|
||||
UserService $userService,
|
||||
UserGroupService $userGroupService,
|
||||
UserProfileService $userProfileService,
|
||||
DatabaseConnectionData $databaseConnectionData)
|
||||
protected function initialize()
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->configData = $config->getConfigData();
|
||||
$this->configService = $configService;
|
||||
$this->userService = $userService;
|
||||
$this->userGroupService = $userGroupService;
|
||||
$this->userProfileService = $userProfileService;
|
||||
$this->databaseConnectionData = $databaseConnectionData;
|
||||
$this->configData = $this->config->getConfigData();
|
||||
$this->configService = $this->dic->get(ConfigService::class);
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @author nuxsmin
|
||||
* @link https://syspass.org
|
||||
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
@@ -22,14 +22,11 @@
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Core\Install;
|
||||
namespace SP\Services\Install;
|
||||
|
||||
use PDOException;
|
||||
use SP\Config\Config;
|
||||
use SP\Config\ConfigData;
|
||||
use SP\Core\Dic\InjectableTrait;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\DataModel\InstallData;
|
||||
use SP\Storage\DatabaseConnectionData;
|
||||
use SP\Storage\DBUtil;
|
||||
use SP\Storage\MySQLHandler;
|
||||
@@ -38,12 +35,10 @@ use SP\Util\Util;
|
||||
/**
|
||||
* Class MySQL
|
||||
*
|
||||
* @package SP\Core\Install
|
||||
* @package SP\Services\Install
|
||||
*/
|
||||
class MySQL implements DatabaseSetupInterface
|
||||
{
|
||||
use InjectableTrait;
|
||||
|
||||
/**
|
||||
* @var InstallData
|
||||
*/
|
||||
@@ -61,14 +56,13 @@ class MySQL implements DatabaseSetupInterface
|
||||
* MySQL constructor.
|
||||
*
|
||||
* @param InstallData $installData
|
||||
* @param ConfigData $configData
|
||||
* @throws SPException
|
||||
* @throws \SP\Core\Dic\ContainerException
|
||||
*/
|
||||
public function __construct(InstallData $installData)
|
||||
public function __construct(InstallData $installData, ConfigData $configData)
|
||||
{
|
||||
$this->injectDependencies();
|
||||
|
||||
$this->installData = $installData;
|
||||
$this->configData = $configData;
|
||||
|
||||
$this->connectDatabase();
|
||||
}
|
||||
@@ -104,14 +98,6 @@ class MySQL implements DatabaseSetupInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
*/
|
||||
public function inject(Config $config)
|
||||
{
|
||||
$this->configData = $config->getConfigData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SPException
|
||||
*/
|
||||
@@ -29,10 +29,10 @@ use Defuse\Crypto\Encoding;
|
||||
use SP\Bootstrap;
|
||||
use SP\Config\ConfigData;
|
||||
use SP\Core\Exceptions\SPException;
|
||||
use SP\Core\Install\Installer;
|
||||
use SP\Html\Html;
|
||||
use SP\Log\Log;
|
||||
use SP\Log\LogUtil;
|
||||
use SP\Services\Install\Installer;
|
||||
|
||||
defined('APP_ROOT') || die();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user