From 4e5ea8ae4306d7e30339f4996bd423a02e58cff7 Mon Sep 17 00:00:00 2001
From: nuxsmin
Date: Mon, 19 Mar 2018 04:01:48 +0100
Subject: [PATCH] * [ADD] Upgrade process. Work in progress.
---
app/modules/api/Init.php | 18 +-
.../web/Controllers/UpgradeController.php | 59 +-
app/modules/web/Init.php | 18 +-
.../material-blue/views/upgrade/index.inc | 39 +
lib/SP/Config/Config.php | 31 +-
lib/SP/Config/ConfigData.php | 27 +-
lib/SP/DataModel/PublicLinkBaseData.php | 132 ---
lib/SP/DataModel/PublickLinkOldData.php | 310 ++++++
.../PublicLink/PublicLinkRepository.php | 26 +-
.../Install/DatabaseSetupInterface.php | 5 +-
lib/SP/Services/Install/Installer.php | 12 +-
lib/SP/Services/Install/MySQL.php | 37 +-
.../Services/PublicLink/PublicLinkService.php | 14 +
lib/SP/Services/Upgrade/UpgradeAppService.php | 38 +-
.../Upgrade/UpgradeCustomFieldDefinition.php | 6 +-
.../Upgrade/UpgradeDatabaseService.php | 23 +-
lib/SP/Services/Upgrade/UpgradePublicLink.php | 123 +++
lib/SP/Storage/DatabaseConnectionData.php | 2 +
lib/SP/Storage/XmlHandler.php | 16 +-
lib/SP/Util/Util.php | 4 +-
public/js/app-actions.js | 4 +-
public/js/app-actions.min.js | 4 +-
schemas/30018010101.sql | 936 ++++++++----------
23 files changed, 1108 insertions(+), 776 deletions(-)
delete mode 100644 lib/SP/DataModel/PublicLinkBaseData.php
create mode 100644 lib/SP/DataModel/PublickLinkOldData.php
create mode 100644 lib/SP/Services/Upgrade/UpgradePublicLink.php
diff --git a/app/modules/api/Init.php b/app/modules/api/Init.php
index 32343b3e..52c3f219 100644
--- a/app/modules/api/Init.php
+++ b/app/modules/api/Init.php
@@ -25,13 +25,11 @@
namespace SP\Modules\Api;
use DI\Container;
-use DI\DependencyException;
use Interop\Container\Exception\NotFoundException;
use SP\Core\Context\StatelessContext;
use SP\Core\Exceptions\InitializationException;
use SP\Core\Language;
use SP\Core\ModuleBase;
-use SP\Services\Config\ConfigService;
use SP\Services\Upgrade\UpgradeAppService;
use SP\Services\Upgrade\UpgradeDatabaseService;
use SP\Services\Upgrade\UpgradeUtil;
@@ -77,6 +75,7 @@ class Init extends ModuleBase
* @throws \DI\NotFoundException
* @throws \SP\Core\Exceptions\SPException
* @throws NotFoundException
+ * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
*/
public function initialize($controller)
{
@@ -124,20 +123,17 @@ class Init extends ModuleBase
/**
* Comprobar si es necesario actualizar componentes
*
- * @throws DependencyException
- * @throws NotFoundException
- * @throws \SP\Services\Config\ParameterNotFoundException
* @throws InitializationException
- * @throws \DI\NotFoundException
+ * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
*/
private function checkUpgrade()
{
- $configService = $this->container->get(ConfigService::class);
- $dbVersion = UpgradeUtil::fixVersionNumber($configService->getByParam('version'));
-
- if (UpgradeDatabaseService::needsUpgrade($dbVersion) ||
- UpgradeAppService::needsUpgrade(UpgradeUtil::fixVersionNumber($this->configData->getConfigVersion()))
+ if ($this->configData->getUpgradeKey()
+ || (UpgradeDatabaseService::needsUpgrade($this->configData->getDatabaseVersion()) ||
+ UpgradeAppService::needsUpgrade(UpgradeUtil::fixVersionNumber($this->configData->getConfigVersion())))
) {
+ $this->config->generateUpgradeKey();
+
throw new InitializationException(__u('Es necesario actualizar'));
}
}
diff --git a/app/modules/web/Controllers/UpgradeController.php b/app/modules/web/Controllers/UpgradeController.php
index b34ff040..145fad23 100644
--- a/app/modules/web/Controllers/UpgradeController.php
+++ b/app/modules/web/Controllers/UpgradeController.php
@@ -24,8 +24,14 @@
namespace SP\Modules\Web\Controllers;
-use SP\Core\Exceptions\SPException;
+use SP\Http\JsonResponse;
+use SP\Http\Request;
use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
+use SP\Modules\Web\Controllers\Traits\JsonTrait;
+use SP\Services\Upgrade\UpgradeAppService;
+use SP\Services\Upgrade\UpgradeDatabaseService;
+use SP\Services\Upgrade\UpgradeException;
+use SP\Services\Upgrade\UpgradeUtil;
/**
* Class UpgradeController
@@ -34,22 +40,55 @@ use SP\Modules\Web\Controllers\Helpers\LayoutHelper;
*/
class UpgradeController extends ControllerBase
{
+ use JsonTrait;
+
/**
* indexAction
*/
public function indexAction()
{
$layoutHelper = $this->dic->get(LayoutHelper::class);
- $layoutHelper->getErrorLayout('upgrade');
-
- $errors[] = [
- 'type' => SPException::WARNING,
- 'description' => __('La aplicación necesita actualizarse'),
- 'hint' => __('Consulte con el administrador')
- ];
-
- $this->view->assign('errors', $errors);
+ $layoutHelper->getPublicLayout('index', 'upgrade');
$this->view();
}
+
+ /**
+ * upgradeAction
+ */
+ public function upgradeAction()
+ {
+ if (Request::analyzeBool('chkConfirm', false) === false) {
+ $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Es necesario confirmar la actualización'));
+ }
+
+ if (Request::analyzeString('key') !== $this->configData->getUpgradeKey()) {
+ $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Código de seguridad incorrecto'));
+ }
+
+
+ try {
+ $dbVersion = $this->configData->getDatabaseVersion();
+ $dbVersion = empty($dbVersion) ? '0.0' : $dbVersion;
+
+ if (UpgradeDatabaseService::needsUpgrade($dbVersion)) {
+ $this->dic->get(UpgradeDatabaseService::class)
+ ->upgrade($dbVersion);
+ }
+
+ if (UpgradeAppService::needsUpgrade(UpgradeUtil::fixVersionNumber($this->configData->getConfigVersion()))) {
+ $this->dic->get(UpgradeAppService::class)
+ ->upgrade(UpgradeUtil::fixVersionNumber($this->configData->getConfigVersion()));
+ }
+
+ $this->configData->setUpgradeKey(null);
+ $this->config->saveConfig($this->configData, false);
+
+ $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Aplicación actualizada correctamente'), [__u('En 5 segundos será redirigido al login')]);
+ } catch (UpgradeException $e) {
+ processException($e);
+
+ $this->returnJsonResponseException($e);
+ }
+ }
}
\ No newline at end of file
diff --git a/app/modules/web/Init.php b/app/modules/web/Init.php
index c43a5489..341223b3 100644
--- a/app/modules/web/Init.php
+++ b/app/modules/web/Init.php
@@ -26,8 +26,6 @@ namespace SP\Modules\Web;
use Defuse\Crypto\Exception\CryptoException;
use DI\Container;
-use DI\DependencyException;
-use DI\NotFoundException;
use SP\Bootstrap;
use SP\Core\Context\ContextException;
use SP\Core\Context\ContextInterface;
@@ -40,7 +38,6 @@ use SP\Core\Language;
use SP\Core\ModuleBase;
use SP\Core\UI\Theme;
use SP\Http\Request;
-use SP\Services\Config\ConfigService;
use SP\Services\Upgrade\UpgradeAppService;
use SP\Services\Upgrade\UpgradeDatabaseService;
use SP\Services\Upgrade\UpgradeUtil;
@@ -99,6 +96,7 @@ class Init extends ModuleBase
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
* @throws \SP\Core\Exceptions\SPException
+ * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
*/
public function initialize($controller)
{
@@ -163,6 +161,8 @@ class Init extends ModuleBase
// Checks if upgrade is needed
if ($this->checkUpgrade()) {
+ $this->config->generateUpgradeKey();
+
$this->router->response()
->redirect('index.php?r=upgrade/index')
->send();
@@ -229,18 +229,12 @@ class Init extends ModuleBase
/**
* Comprobar si es necesario actualizar componentes
- *
- * @throws DependencyException
- * @throws NotFoundException
- * @throws \SP\Services\Config\ParameterNotFoundException
*/
private function checkUpgrade()
{
- $configService = $this->container->get(ConfigService::class);
- $dbVersion = UpgradeUtil::fixVersionNumber($configService->getByParam('version'));
-
- return UpgradeDatabaseService::needsUpgrade($dbVersion) ||
- UpgradeAppService::needsUpgrade(UpgradeUtil::fixVersionNumber($this->configData->getConfigVersion()));
+ return $this->configData->getUpgradeKey()
+ || (UpgradeDatabaseService::needsUpgrade($this->configData->getDatabaseVersion()) ||
+ UpgradeAppService::needsUpgrade(UpgradeUtil::fixVersionNumber($this->configData->getConfigVersion())));
}
/**
diff --git a/app/modules/web/themes/material-blue/views/upgrade/index.inc b/app/modules/web/themes/material-blue/views/upgrade/index.inc
index c4d81ff6..7d0f39ee 100644
--- a/app/modules/web/themes/material-blue/views/upgrade/index.inc
+++ b/app/modules/web/themes/material-blue/views/upgrade/index.inc
@@ -1,6 +1,7 @@
@@ -11,6 +12,44 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/lib/SP/Config/Config.php b/lib/SP/Config/Config.php
index a9d5bbed..14b3b326 100644
--- a/lib/SP/Config/Config.php
+++ b/lib/SP/Config/Config.php
@@ -32,6 +32,7 @@ use SP\Core\Exceptions\FileNotFoundException;
use SP\Services\Config\ConfigBackupService;
use SP\Storage\XmlFileStorageInterface;
use SP\Storage\XmlHandler;
+use SP\Util\Util;
defined('APP_ROOT') || die();
@@ -65,8 +66,8 @@ class Config
* Config constructor.
*
* @param XmlFileStorageInterface $fileStorage
- * @param ContextInterface $session
- * @param Container $dic
+ * @param ContextInterface $session
+ * @param Container $dic
* @throws ConfigException
*/
public function __construct(XmlFileStorageInterface $fileStorage, ContextInterface $session, Container $dic)
@@ -125,15 +126,15 @@ class Config
* Guardar la configuración
*
* @param ConfigData $configData
- * @param bool $backup
+ * @param bool $backup
+ * @return Config
*/
public function saveConfig(ConfigData $configData, $backup = true)
{
try {
if ($backup) {
-
- $this->dic->get(ConfigBackupService::class)->backup();
-
+ $this->dic->get(ConfigBackupService::class)
+ ->backup();
}
$configData->setConfigDate(time());
@@ -145,13 +146,15 @@ class Config
} catch (\Exception $e) {
processException($e);
}
+
+ return $this;
}
/**
* Cargar la configuración desde el archivo
*
* @param ContextInterface $context
- * @param bool $reload
+ * @param bool $reload
* @return ConfigData
*/
public function loadConfig(ContextInterface $context, $reload = false)
@@ -189,4 +192,18 @@ class Config
{
return clone $this->configData;
}
+
+ /**
+ * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
+ */
+ public function generateUpgradeKey()
+ {
+ if (empty($this->configData->getUpgradeKey())) {
+ debugLog('Generating upgrade key');
+
+ return $this->saveConfig($this->configData->setUpgradeKey(Util::generateRandomBytes(16)), false);
+ }
+
+ return $this;
+ }
}
diff --git a/lib/SP/Config/ConfigData.php b/lib/SP/Config/ConfigData.php
index 84db62ed..f439da6a 100644
--- a/lib/SP/Config/ConfigData.php
+++ b/lib/SP/Config/ConfigData.php
@@ -289,6 +289,10 @@ class ConfigData implements JsonSerializable
* @var string
*/
private $configVersion;
+ /**
+ * @var string
+ */
+ private $databaseVersion;
/**
* @var bool
*/
@@ -1520,11 +1524,11 @@ class ConfigData implements JsonSerializable
*/
public function getConfigVersion()
{
- return $this->configVersion;
+ return (string)$this->configVersion;
}
/**
- * @param int $configVersion
+ * @param string $configVersion
* @return $this
*/
public function setConfigVersion($configVersion)
@@ -1989,4 +1993,23 @@ class ConfigData implements JsonSerializable
{
$this->mailEvents = $mailEvents;
}
+
+ /**
+ * @return string
+ */
+ public function getDatabaseVersion()
+ {
+ return (string)$this->databaseVersion;
+ }
+
+ /**
+ * @param string $databaseVersion
+ * @return ConfigData
+ */
+ public function setDatabaseVersion($databaseVersion)
+ {
+ $this->databaseVersion = $databaseVersion;
+
+ return $this;
+ }
}
\ No newline at end of file
diff --git a/lib/SP/DataModel/PublicLinkBaseData.php b/lib/SP/DataModel/PublicLinkBaseData.php
deleted file mode 100644
index b0660a6a..00000000
--- a/lib/SP/DataModel/PublicLinkBaseData.php
+++ /dev/null
@@ -1,132 +0,0 @@
-.
- */
-
-namespace SP\DataModel;
-
-defined('APP_ROOT') || die();
-
-/**
- * Class PublicLinkBaseData
- *
- * @package SP\DataModel
- */
-class PublicLinkBaseData extends DataModelBase implements DataModelInterface
-{
- /**
- * @var int
- */
- public $publicLink_id = 0;
- /**
- * @var int
- */
- public $publicLink_itemId = 0;
- /**
- * @var string
- */
- public $publicLink_hash = '';
- /**
- * @var PublicLinkData
- */
- public $publicLink_linkData;
-
- /**
- * @return int
- */
- public function getPublicLinkId()
- {
- return (int)$this->publicLink_id;
- }
-
- /**
- * @param int $publicLink_id
- */
- public function setPublicLinkId($publicLink_id)
- {
- $this->publicLink_id = (int)$publicLink_id;
- }
-
- /**
- * @return string
- */
- public function getPublicLinkHash()
- {
- return $this->publicLink_hash;
- }
-
- /**
- * @param string $publicLink_hash
- */
- public function setPublicLinkHash($publicLink_hash)
- {
- $this->publicLink_hash = $publicLink_hash;
- }
-
- /**
- * @return PublicLinkData
- */
- public function getPublicLinkLinkData()
- {
- return $this->publicLink_linkData;
- }
-
- /**
- * @param PublicLinkData $publicLink_linkData
- */
- public function setPublicLinkLinkData($publicLink_linkData)
- {
- $this->publicLink_linkData = $publicLink_linkData;
- }
-
- /**
- * @return int
- */
- public function getPublicLinkItemId()
- {
- return (int)$this->publicLink_itemId;
- }
-
- /**
- * @param int $publicLink_itemId
- */
- public function setPublicLinkItemId($publicLink_itemId)
- {
- $this->publicLink_itemId = (int)$publicLink_itemId;
- }
-
- /**
- * @return int
- */
- public function getId()
- {
- return $this->publicLink_id;
- }
-
- /**
- * @return string
- */
- public function getName()
- {
- return '';
- }
-}
\ No newline at end of file
diff --git a/lib/SP/DataModel/PublickLinkOldData.php b/lib/SP/DataModel/PublickLinkOldData.php
new file mode 100644
index 00000000..6774002d
--- /dev/null
+++ b/lib/SP/DataModel/PublickLinkOldData.php
@@ -0,0 +1,310 @@
+.
+ */
+
+namespace SP\DataModel;
+
+/**
+ * Class PublickLinkOldData
+ *
+ * @package SP\DataModel
+ */
+class PublickLinkOldData
+{
+ /**
+ * @var int
+ */
+ protected $itemId = 0;
+ /**
+ * @var int
+ */
+ protected $userId = 0;
+ /**
+ * @var string
+ */
+ protected $linkHash = '';
+ /**
+ * @var int
+ */
+ protected $typeId = 0;
+ /**
+ * @var bool
+ */
+ protected $notify = false;
+ /**
+ * @var int
+ */
+ protected $dateAdd = 0;
+ /**
+ * @var int
+ */
+ protected $dateExpire = 0;
+ /**
+ * @var string
+ */
+ protected $pass = '';
+ /**
+ * @var string
+ */
+ protected $passIV = '';
+ /**
+ * @var int
+ */
+ protected $countViews = 0;
+ /**
+ * @var int
+ */
+ protected $maxCountViews = 0;
+ /**
+ * @var array
+ */
+ protected $useInfo = [];
+ /**
+ * @var string
+ */
+ protected $data;
+
+ /**
+ * @return int
+ */
+ public function getItemId()
+ {
+ return $this->itemId;
+ }
+
+ /**
+ * @param int $itemId
+ */
+ public function setItemId($itemId)
+ {
+ $this->itemId = $itemId;
+ }
+
+ /**
+ * @return int
+ */
+ public function getUserId()
+ {
+ return $this->userId;
+ }
+
+ /**
+ * @param int $userId
+ */
+ public function setUserId($userId)
+ {
+ $this->userId = $userId;
+ }
+
+ /**
+ * @return string
+ */
+ public function getLinkHash()
+ {
+ return $this->linkHash;
+ }
+
+ /**
+ * @param string $linkHash
+ */
+ public function setLinkHash($linkHash)
+ {
+ $this->linkHash = $linkHash;
+ }
+
+ /**
+ * @return int
+ */
+ public function getTypeId()
+ {
+ return $this->typeId;
+ }
+
+ /**
+ * @param int $typeId
+ */
+ public function setTypeId($typeId)
+ {
+ $this->typeId = $typeId;
+ }
+
+ /**
+ * @return boolean
+ */
+ public function isNotify()
+ {
+ return (bool)$this->notify;
+ }
+
+ /**
+ * @param boolean $notify
+ */
+ public function setNotify($notify)
+ {
+ $this->notify = $notify;
+ }
+
+ /**
+ * @return int
+ */
+ public function getDateAdd()
+ {
+ return $this->dateAdd;
+ }
+
+ /**
+ * @param int $dateAdd
+ */
+ public function setDateAdd($dateAdd)
+ {
+ $this->dateAdd = $dateAdd;
+ }
+
+ /**
+ * @return int
+ */
+ public function getDateExpire()
+ {
+ return $this->dateExpire;
+ }
+
+ /**
+ * @param int $dateExpire
+ */
+ public function setDateExpire($dateExpire)
+ {
+ $this->dateExpire = $dateExpire;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPass()
+ {
+ return $this->pass;
+ }
+
+ /**
+ * @param string $pass
+ */
+ public function setPass($pass)
+ {
+ $this->pass = $pass;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPassIV()
+ {
+ return $this->passIV;
+ }
+
+ /**
+ * @param string $passIV
+ */
+ public function setPassIV($passIV)
+ {
+ $this->passIV = $passIV;
+ }
+
+ /**
+ * @return int
+ */
+ public function getCountViews()
+ {
+ return $this->countViews;
+ }
+
+ /**
+ * @param int $countViews
+ */
+ public function setCountViews($countViews)
+ {
+ $this->countViews = $countViews;
+ }
+
+ /**
+ * @return int
+ */
+ public function addCountViews()
+ {
+ return $this->countViews++;
+ }
+
+ /**
+ * @return int
+ */
+ public function getMaxCountViews()
+ {
+ return $this->maxCountViews;
+ }
+
+ /**
+ * @param int $maxCountViews
+ */
+ public function setMaxCountViews($maxCountViews)
+ {
+ $this->maxCountViews = $maxCountViews;
+ }
+
+ /**
+ * @return array
+ */
+ public function getUseInfo()
+ {
+ return $this->useInfo;
+ }
+
+ /**
+ * @param array $useInfo
+ */
+ public function setUseInfo(array $useInfo)
+ {
+ $this->useInfo = $useInfo;
+ }
+
+ /**
+ * @param array $useInfo
+ */
+ public function addUseInfo($useInfo)
+ {
+ $this->useInfo[] = $useInfo;
+ }
+
+ /**
+ * @return string
+ */
+ public function getData()
+ {
+ return $this->data;
+ }
+
+ /**
+ * @param string $data
+ */
+ public function setData($data)
+ {
+ $this->data = $data;
+ }
+}
\ No newline at end of file
diff --git a/lib/SP/Repositories/PublicLink/PublicLinkRepository.php b/lib/SP/Repositories/PublicLink/PublicLinkRepository.php
index 68c3b3be..bfd7352b 100644
--- a/lib/SP/Repositories/PublicLink/PublicLinkRepository.php
+++ b/lib/SP/Repositories/PublicLink/PublicLinkRepository.php
@@ -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.
@@ -245,7 +245,7 @@ class PublicLinkRepository extends Repository implements RepositoryItemInterface
'INSERT INTO PublicLink
SET itemId = ?,
`hash` = ?,
- data = ?,
+ `data` = ?,
userId = ?,
typeId = ?,
notify = ?,
@@ -337,20 +337,32 @@ class PublicLinkRepository extends Repository implements RepositoryItemInterface
{
$query = /** @lang SQL */
'UPDATE PublicLink
- SET `hash` = ?,
- data = ?,
+ SET itemId = ?,
+ `hash` = ?,
+ `data` = ?,
+ userId = ?,
notify = ?,
+ dateAdd = ?,
dateExpire = ?,
- maxCountViews = ?
+ countViews = ?,
+ maxCountViews = ?,
+ useInfo = ?,
+ typeId = ?
WHERE id = ? LIMIT 1';
$queryData = new QueryData();
$queryData->setQuery($query);
+ $queryData->addParam($itemData->getItemId());
$queryData->addParam($itemData->getHash());
$queryData->addParam($itemData->getData());
+ $queryData->addParam($itemData->getUserId());
$queryData->addParam((int)$itemData->isNotify());
+ $queryData->addParam($itemData->getDateAdd());
$queryData->addParam($itemData->getDateExpire());
+ $queryData->addParam($itemData->getCountViews());
$queryData->addParam($itemData->getMaxCountViews());
+ $queryData->addParam($itemData->getUseInfo());
+ $queryData->addParam($itemData->getTypeId());
$queryData->addParam($itemData->getId());
$queryData->setOnErrorMessage(__u('Error al actualizar enlace'));
@@ -371,7 +383,7 @@ class PublicLinkRepository extends Repository implements RepositoryItemInterface
$query = /** @lang SQL */
'UPDATE PublicLink
SET `hash` = ?,
- data = ?,
+ `data` = ?,
dateExpire = ?,
countViews = 0,
maxCountViews = ?
diff --git a/lib/SP/Services/Install/DatabaseSetupInterface.php b/lib/SP/Services/Install/DatabaseSetupInterface.php
index ce839fae..c2c03d9c 100644
--- a/lib/SP/Services/Install/DatabaseSetupInterface.php
+++ b/lib/SP/Services/Install/DatabaseSetupInterface.php
@@ -47,8 +47,11 @@ interface DatabaseSetupInterface
/**
* Crear el usuario para conectar con la base de datos.
* Esta función crea el usuario para conectar con la base de datos.
+ *
+ * @param string $user
+ * @param string $pass
*/
- public function createDBUser();
+ public function createDBUser($user, $pass);
/**
* Crear la base de datos
diff --git a/lib/SP/Services/Install/Installer.php b/lib/SP/Services/Install/Installer.php
index 0991d136..e3b6d1a8 100644
--- a/lib/SP/Services/Install/Installer.php
+++ b/lib/SP/Services/Install/Installer.php
@@ -78,7 +78,6 @@ class Installer extends Service
/**
* @param InstallData $installData
* @return static
- * @throws Dic\ContainerException
* @throws InvalidArgumentException
* @throws SPException
* @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
@@ -167,7 +166,6 @@ class Installer extends Service
/**
* Iniciar instalación.
*
- * @throws Dic\ContainerException
* @throws SPException
* @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
* @throws \Psr\Container\ContainerExceptionInterface
@@ -185,9 +183,14 @@ class Installer extends Service
$this->saveMasterPassword();
$this->createAdminAccount();
- $this->configService->create(new \SP\DataModel\ConfigData('version', Util::getVersionStringNormalized()));
+ $version = Util::getVersionStringNormalized();
+
+ $this->configService->create(new \SP\DataModel\ConfigData('version', $version));
$this->configData->setInstalled(true);
+ $this->configData->setDatabaseVersion($version);
+ $this->configData->setConfigVersion($version);
+
$this->config->saveConfig($this->configData, false);
}
@@ -270,7 +273,8 @@ class Installer extends Service
private function setupDBConnectionData()
{
// FIXME: ugly!!
- $this->dic->get(DatabaseConnectionData::class)->refreshFromConfig($this->configData);
+ $this->dic->get(DatabaseConnectionData::class)
+ ->refreshFromConfig($this->configData);
}
/**
diff --git a/lib/SP/Services/Install/MySQL.php b/lib/SP/Services/Install/MySQL.php
index 08e75079..742a7f13 100644
--- a/lib/SP/Services/Install/MySQL.php
+++ b/lib/SP/Services/Install/MySQL.php
@@ -103,60 +103,63 @@ class MySQL implements DatabaseSetupInterface
*/
public function setupDbUser()
{
- $this->installData->setDbPass(Util::randomPassword());
- $this->installData->setDbUser(substr(uniqid('sp_'), 0, 16));
+ debugLog(__METHOD__);
+
+ $user = substr(uniqid('sp_'), 0, 16);
+ $pass = Util::randomPassword();
try {
// Comprobar si el usuario proporcionado existe
$sth = $this->dbs->getConnectionSimple()
->prepare('SELECT COUNT(*) FROM mysql.user WHERE `user` = ? AND `host` = ?');
- $sth->execute([$this->installData->getDbUser(), $this->installData->getDbAuthHost()]);
+ $sth->execute([$user, $pass]);
// Si no existe el usuario, se intenta crear
- if ((int)$sth->fetchColumn() === 0
- // Se comprueba si el nuevo usuario es distinto del creado en otra instalación
- && $this->installData->getDbUser() !== $this->configData->getDbUser()
- ) {
- $this->createDBUser();
+ if ((int)$sth->fetchColumn() === 0) {
+ $this->createDBUser($user, $pass);
}
} catch (PDOException $e) {
processException($e);
throw new SPException(
- sprintf(__('No es posible comprobar el usuario de sysPass (%s)'), $this->installData->getAdminLogin()),
+ sprintf(__('No es posible comprobar el usuario de sysPass (%s)'), $user),
SPException::CRITICAL,
__u('Compruebe los permisos del usuario de conexión a la BD')
);
}
// Guardar el nuevo usuario/clave de conexión a la BD
- $this->configData->setDbUser($this->installData->getDbUser());
- $this->configData->setDbPass($this->installData->getDbPass());
+ $this->configData->setDbUser($user);
+ $this->configData->setDbPass($pass);
}
/**
* Crear el usuario para conectar con la base de datos.
* Esta función crea el usuario para conectar con la base de datos.
*
+ * @param string $user
+ * @param string $pass
* @throws SPException
*/
- public function createDBUser()
+ public function createDBUser($user, $pass)
{
if ($this->installData->isHostingMode()) {
return;
}
+ debugLog('Creating DB user');
+
try {
$dbc = $this->dbs->getConnectionSimple();
- $dbc->exec('CREATE USER `' . $this->installData->getDbUser() . '`@`' . $this->installData->getDbAuthHost() . '` IDENTIFIED BY \'' . $this->installData->getDbPass() . '\'');
- $dbc->exec('CREATE USER `' . $this->installData->getDbUser() . '`@`' . $this->installData->getDbAuthHostDns() . '` IDENTIFIED BY \'' . $this->installData->getDbPass() . '\'');
+ $dbc->exec('CREATE USER `' . $user . '`@`' . $this->installData->getDbAuthHost() . '` IDENTIFIED BY \'' . $pass . '\'');
+ $dbc->exec('CREATE USER `' . $user . '`@`' . $this->installData->getDbAuthHostDns() . '` IDENTIFIED BY \'' . $pass . '\'');
$dbc->exec('FLUSH PRIVILEGES');
} catch (PDOException $e) {
processException($e);
throw new SPException(
- sprintf(__u('Error al crear el usuario de conexión a MySQL \'%s\''), $this->installData->getDbUser()),
+ sprintf(__u('Error al crear el usuario de conexión a MySQL \'%s\''), $user),
SPException::CRITICAL, $e->getMessage()
);
}
@@ -291,9 +294,7 @@ class MySQL implements DatabaseSetupInterface
}
// Leemos el archivo SQL para crear las tablas de la BBDD
- $handle = fopen($fileName, 'rb');
-
- if ($handle) {
+ if ($handle = fopen($fileName, 'rb')) {
while (!feof($handle)) {
$buffer = stream_get_line($handle, 1000000, ";\n");
diff --git a/lib/SP/Services/PublicLink/PublicLinkService.php b/lib/SP/Services/PublicLink/PublicLinkService.php
index 400c04db..b8a6171e 100644
--- a/lib/SP/Services/PublicLink/PublicLinkService.php
+++ b/lib/SP/Services/PublicLink/PublicLinkService.php
@@ -325,6 +325,20 @@ class PublicLinkService extends Service
return $this->publicLinkRepository->getHashForItem($itemId);
}
+ /**
+ * Updates an item
+ *
+ * @param PublicLinkData $itemData
+ * @return mixed
+ * @throws SPException
+ * @throws \SP\Core\Exceptions\ConstraintException
+ * @throws \SP\Core\Exceptions\QueryException
+ */
+ public function update(PublicLinkData $itemData)
+ {
+ return $this->publicLinkRepository->update($itemData);
+ }
+
/**
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
diff --git a/lib/SP/Services/Upgrade/UpgradeAppService.php b/lib/SP/Services/Upgrade/UpgradeAppService.php
index 0830e6c0..5bdb3ac6 100644
--- a/lib/SP/Services/Upgrade/UpgradeAppService.php
+++ b/lib/SP/Services/Upgrade/UpgradeAppService.php
@@ -24,6 +24,8 @@
namespace SP\Services\Upgrade;
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
use SP\Services\Service;
use SP\Util\Util;
@@ -51,17 +53,35 @@ class UpgradeAppService extends Service implements UpgradeInterface
*/
public function upgrade($version)
{
+ $this->eventDispatcher->notifyEvent('upgrade.app.start',
+ new Event($this, EventMessage::factory()
+ ->addDescription(__u('Actualizar Aplicación')))
+ );
+
+ $configData = $this->config->getConfigData();
+
foreach (self::UPGRADES as $appVersion) {
- if (Util::checkVersion($version, $appVersion)
- && $this->applyUpgrade($appVersion) === false
- ) {
- throw new UpgradeException(
- __u('Error al aplicar la actualización de la aplicación'),
- UpgradeException::CRITICAL,
- __u('Compruebe el registro de eventos para más detalles')
- );
+ if (Util::checkVersion($version, $appVersion)) {
+ if ($this->applyUpgrade($appVersion) === false) {
+ throw new UpgradeException(
+ __u('Error al aplicar la actualización de la aplicación'),
+ UpgradeException::CRITICAL,
+ __u('Compruebe el registro de eventos para más detalles')
+ );
+ }
+
+ debugLog('APP Upgrade: '. $appVersion);
+
+ $configData->setConfigVersion($appVersion);
}
}
+
+ $this->config->saveConfig($configData, false);
+
+ $this->eventDispatcher->notifyEvent('upgrade.app.end',
+ new Event($this, EventMessage::factory()
+ ->addDescription(__u('Actualizar Aplicación')))
+ );
}
/**
@@ -77,6 +97,8 @@ class UpgradeAppService extends Service implements UpgradeInterface
case '300.18010101':
$this->dic->get(UpgradeCustomFieldDefinition::class)
->upgrade_300_18010101();
+ $this->dic->get(UpgradePublicLink::class)
+ ->upgrade_300_18010101();
return true;
}
} catch (\Exception $e) {
diff --git a/lib/SP/Services/Upgrade/UpgradeCustomFieldDefinition.php b/lib/SP/Services/Upgrade/UpgradeCustomFieldDefinition.php
index bb898fc0..780d76ce 100644
--- a/lib/SP/Services/Upgrade/UpgradeCustomFieldDefinition.php
+++ b/lib/SP/Services/Upgrade/UpgradeCustomFieldDefinition.php
@@ -32,7 +32,7 @@ use SP\Services\CustomField\CustomFieldDefService;
use SP\Services\CustomField\CustomFieldTypeService;
use SP\Services\Service;
use SP\Services\ServiceException;
-use SP\Storage\DatabaseInterface;
+use SP\Storage\Database;
use SP\Storage\DbWrapper;
use SP\Storage\QueryData;
use SP\Util\Util;
@@ -45,7 +45,7 @@ use SP\Util\Util;
class UpgradeCustomFieldDefinition extends Service
{
/**
- * @var DatabaseInterface
+ * @var Database
*/
private $db;
@@ -121,6 +121,6 @@ class UpgradeCustomFieldDefinition extends Service
protected function initialize()
{
- $this->db = $this->dic->get(DatabaseInterface::class);
+ $this->db = $this->dic->get(Database::class);
}
}
\ No newline at end of file
diff --git a/lib/SP/Services/Upgrade/UpgradeDatabaseService.php b/lib/SP/Services/Upgrade/UpgradeDatabaseService.php
index 65d5d2ad..7d4cadca 100644
--- a/lib/SP/Services/Upgrade/UpgradeDatabaseService.php
+++ b/lib/SP/Services/Upgrade/UpgradeDatabaseService.php
@@ -26,7 +26,6 @@ namespace SP\Services\Upgrade;
use SP\Core\Events\Event;
use SP\Core\Events\EventMessage;
-use SP\Services\Config\ConfigService;
use SP\Services\Service;
use SP\Storage\Database;
use SP\Storage\DbWrapper;
@@ -58,7 +57,7 @@ class UpgradeDatabaseService extends Service implements UpgradeInterface
*/
public static function needsUpgrade($version)
{
- return Util::checkVersion($version, self::UPGRADES);
+ return empty($version) || Util::checkVersion($version, self::UPGRADES);
}
/**
@@ -67,8 +66,6 @@ class UpgradeDatabaseService extends Service implements UpgradeInterface
* @param int $version con la versión de la BBDD actual
* @return bool
* @throws UpgradeException
- * @throws \SP\Core\Exceptions\SPException
- * @throws \SP\Services\Config\ParameterNotFoundException
*/
public function upgrade($version)
{
@@ -77,13 +74,10 @@ class UpgradeDatabaseService extends Service implements UpgradeInterface
->addDescription(__u('Actualizar BBDD')))
);
- $configService = $this->dic->get(ConfigService::class);
- $dbVersion = UpgradeUtil::fixVersionNumber($configService->getByParam('version'));
+ $configData = $this->config->getConfigData();
foreach (self::UPGRADES as $upgradeVersion) {
- if (Util::checkVersion($version, $upgradeVersion)
- && Util::checkVersion($dbVersion, $version)
- ) {
+ if (Util::checkVersion($version, $upgradeVersion)) {
if ($this->applyPreUpgrade($upgradeVersion) === false) {
throw new UpgradeException(
__u('Error al aplicar la actualización auxiliar'),
@@ -100,7 +94,11 @@ class UpgradeDatabaseService extends Service implements UpgradeInterface
);
}
- $configService->save('version', $version);
+ debugLog('DB Upgrade: ' . $upgradeVersion);
+
+ $configData->setDatabaseVersion($upgradeVersion);
+
+ $this->config->saveConfig($configData, false);
}
}
@@ -169,6 +167,7 @@ class UpgradeDatabaseService extends Service implements UpgradeInterface
DbWrapper::getQuery($queryData, $this->db);
} catch (\Exception $e) {
processException($e);
+ debugLog('SQL: ' . $query);
$this->eventDispatcher->notifyEvent('exception',
new Event($this, EventMessage::factory()
@@ -206,8 +205,8 @@ class UpgradeDatabaseService extends Service implements UpgradeInterface
while (!feof($handle)) {
$buffer = stream_get_line($handle, 1000000, ";\n");
- if (strlen(trim($buffer)) > 0) {
- $queries[] = str_replace("\n", '', $buffer);
+ if (strlen(trim($buffer)) > 0 && strpos($buffer, '--') !== 0) {
+ $queries[] = $buffer;
}
}
}
diff --git a/lib/SP/Services/Upgrade/UpgradePublicLink.php b/lib/SP/Services/Upgrade/UpgradePublicLink.php
new file mode 100644
index 00000000..c071f87e
--- /dev/null
+++ b/lib/SP/Services/Upgrade/UpgradePublicLink.php
@@ -0,0 +1,123 @@
+.
+ */
+
+namespace SP\Services\Upgrade;
+
+use SP\Core\Events\Event;
+use SP\Core\Events\EventMessage;
+use SP\DataModel\PublickLinkOldData;
+use SP\DataModel\PublicLinkData;
+use SP\Services\PublicLink\PublicLinkService;
+use SP\Services\Service;
+use SP\Services\ServiceException;
+use SP\Storage\Database;
+use SP\Storage\DbWrapper;
+use SP\Storage\QueryData;
+use SP\Util\Util;
+
+/**
+ * Class UpgradePublicLink
+ *
+ * @package SP\Services\Upgrade
+ */
+class UpgradePublicLink extends Service
+{
+ /**
+ * @var Database
+ */
+ private $db;
+
+ /**
+ * upgrade_300_18010101
+ *
+ * @throws \SP\Core\Exceptions\SPException
+ */
+ public function upgrade_300_18010101()
+ {
+ $this->eventDispatcher->notifyEvent('upgrade.publicLink.start',
+ new Event($this, EventMessage::factory()
+ ->addDescription(__u('Actualización de enlaces públicos'))
+ ->addDescription(__FUNCTION__))
+ );
+
+ $queryData = new QueryData();
+ $queryData->setQuery('SELECT id, `data` FROM PublicLink');
+
+ try {
+ $publicLinkService = $this->dic->get(PublicLinkService::class);
+
+ if (!DbWrapper::beginTransaction($this->db)) {
+ throw new ServiceException(__u('No es posible iniciar una transacción'));
+ }
+
+ foreach (DbWrapper::getResultsArray($queryData, $this->db) as $item) {
+ /** @var PublickLinkOldData $data */
+ $data = Util::unserialize(PublickLinkOldData::class, $item->data, 'SP\DataModel\PublicLinkData');
+
+ $itemData = new PublicLinkData();
+ $itemData->setId($item->id);
+ $itemData->setItemId($data->getItemId());
+ $itemData->setHash($data->getLinkHash());
+ $itemData->setUserId($data->getUserId());
+ $itemData->setTypeId($data->getTypeId());
+ $itemData->setNotify($data->isNotify());
+ $itemData->setDateAdd($data->getDateAdd());
+ $itemData->setDateExpire($data->getDateExpire());
+ $itemData->setCountViews($data->getCountViews());
+ $itemData->setMaxCountViews($data->getMaxCountViews());
+ $itemData->setUseInfo($data->getUseInfo());
+ $itemData->setData($data->getData());
+
+ $publicLinkService->update($itemData);
+
+ $this->eventDispatcher->notifyEvent('upgrade.publicLink.process',
+ new Event($this, EventMessage::factory()
+ ->addDescription(__u('Enlace actualizado'))
+ ->addDetail(__u('Enlace'), $item->id))
+ );
+ }
+
+ if (!DbWrapper::endTransaction($this->db)) {
+ throw new ServiceException(__u('No es posible finalizar una transacción'));
+ }
+ } catch (\Exception $e) {
+ DbWrapper::rollbackTransaction($this->db);
+
+ processException($e);
+
+ $this->eventDispatcher->notifyEvent('exception', new Event($e));
+ }
+
+ $this->eventDispatcher->notifyEvent('upgrade.publicLink.end',
+ new Event($this, EventMessage::factory()
+ ->addDescription(__u('Actualización de enlaces públicos'))
+ ->addDescription(__FUNCTION__))
+ );
+ }
+
+ protected function initialize()
+ {
+ $this->db = $this->dic->get(Database::class);
+ }
+}
\ No newline at end of file
diff --git a/lib/SP/Storage/DatabaseConnectionData.php b/lib/SP/Storage/DatabaseConnectionData.php
index b4ff18c8..a4e086fe 100644
--- a/lib/SP/Storage/DatabaseConnectionData.php
+++ b/lib/SP/Storage/DatabaseConnectionData.php
@@ -79,6 +79,8 @@ class DatabaseConnectionData
*/
public function refreshFromConfig(ConfigData $configData)
{
+ debugLog('Refresh DB connection data');
+
return $this->setDbHost($configData->getDbHost())
->setDbName($configData->getDbName())
->setDbUser($configData->getDbUser())
diff --git a/lib/SP/Storage/XmlHandler.php b/lib/SP/Storage/XmlHandler.php
index 4ca76daa..5dc0cbb5 100644
--- a/lib/SP/Storage/XmlHandler.php
+++ b/lib/SP/Storage/XmlHandler.php
@@ -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.
@@ -127,7 +127,7 @@ class XmlHandler implements XmlFileStorageInterface
$nodes[$node->nodeName] = $this->readChildNodes($node->childNodes);
}
} else {
- $val = is_numeric($node->nodeValue) ? (int)$node->nodeValue : $node->nodeValue;
+ $val = is_numeric($node->nodeValue) && strpos($node->nodeValue, '.') === false ? (int)$node->nodeValue : $node->nodeValue;
if ($node->nodeName === 'item') {
$nodes[] = $val;
@@ -181,9 +181,9 @@ class XmlHandler implements XmlFileStorageInterface
/**
* Crear los nodos hijos recursivamente a partir de un array multidimensional
*
- * @param mixed $items
+ * @param mixed $items
* @param DOMNode $Node
- * @param null $type
+ * @param null $type
*/
protected function writeChildNodes($items, DOMNode $Node, $type = null)
{
@@ -212,7 +212,7 @@ class XmlHandler implements XmlFileStorageInterface
* Analizar el tipo de elementos
*
* @param mixed $items
- * @param bool $serialize
+ * @param bool $serialize
* @return array
*/
protected function analyzeItems($items, $serialize = false)
@@ -246,8 +246,10 @@ class XmlHandler implements XmlFileStorageInterface
$property->setAccessible(true);
$value = $property->getValue($object);
- if (is_numeric($value) || is_bool($value)) {
+ if (is_bool($value)) {
$items[$property->getName()] = (int)$value;
+ } elseif (is_numeric($value)) {
+ $items[$property->getName()] = strpos($value, '.') !== false ? (float)$value : (int)$value;
} else {
$items[$property->getName()] = $value;
}
diff --git a/lib/SP/Util/Util.php b/lib/SP/Util/Util.php
index 94282298..099b6a37 100644
--- a/lib/SP/Util/Util.php
+++ b/lib/SP/Util/Util.php
@@ -351,7 +351,7 @@ class Util
list($currentVersion, $build) = explode('.', $currentVersion, 2);
list($upgradeVersion, $upgradeBuild) = explode('.', $upgradeableVersion, 2);
- $versionRes = (int)$currentVersion <= (int)$upgradeVersion;
+ $versionRes = (int)$currentVersion < (int)$upgradeVersion;
return (($versionRes && (int)$upgradeBuild === 0)
|| ($versionRes && (int)$build < (int)$upgradeBuild));
@@ -500,7 +500,7 @@ class Util
if (!is_object($serialized)) {
preg_match('/^O:\d+:"(?P[^"]++)"/', $serialized, $matches);
- if (class_exists($matches['class'])) {
+ if (class_exists($matches['class']) && $srcClass === null) {
return unserialize($serialized);
}
diff --git a/public/js/app-actions.js b/public/js/app-actions.js
index d418055f..2a3d6818 100644
--- a/public/js/app-actions.js
+++ b/public/js/app-actions.js
@@ -665,7 +665,7 @@ sysPass.Actions = function (Common) {
}
const opts = Common.appRequests().getRequestOpts();
- opts.url = ajaxUrl.entrypoint;
+ opts.url = ajaxUrl.entrypoint + "?r=" + $obj.data('action-route');
opts.method = "get";
opts.useFullLoading = !!taskId;
opts.data = $obj.serialize();
@@ -674,7 +674,7 @@ sysPass.Actions = function (Common) {
Common.msg.out(json);
if (json.status !== 0) {
- $obj.find(":input[name=h]").val("");
+ $obj.find(":input[name=key]").val("");
} else {
if (taskRunner !== undefined) {
taskRunner.close();
diff --git a/public/js/app-actions.min.js b/public/js/app-actions.min.js
index 64c7209d..1f812964 100644
--- a/public/js/app-actions.min.js
+++ b/public/js/app-actions.min.js
@@ -16,8 +16,8 @@ void 0!==a.data.itemId&&void 0!==a.data.nextAction&&h(b.appRequests().getRouteFo
update:function(a){e.info("items:update");var c=$("#"+a.data("item-dst"))[0].selectize;c.clearOptions();c.load(function(c){var d=b.appRequests().getRequestOpts();d.url=f.entrypoint;d.method="get";d.data={r:a.data("item-route"),sk:b.sk.get()};b.appRequests().getActionCall(d,function(a){c(a)})})}},u={logout:function(){b.redirect("index.php?r=login/logout")},login:function(a){e.info("main:login");var c=b.appRequests().getRequestOpts();c.url=f.entrypoint+"?r="+a.data("route");c.method="get";c.data=a.serialize();
b.appRequests().getActionCall(c,function(c){var d=$(".extra-hidden");switch(c.status){case 0:b.redirect(c.data.url);break;case 2:b.msg.out(c);a.find("input[type='text'],input[type='password']").val("");a.find("input:first").focus();0";mdlDialog().show({text:c,negative:{title:b.config().LANG[44],onClick:function(a){a.preventDefault();b.msg.error(b.config().LANG[44])}},positive:{title:b.config().LANG[43],onClick:function(c){var d;(c=a.find("input[name='taskId']").val())&&(d=t(c));var e=b.appRequests().getRequestOpts();e.url=f.entrypoint;e.method="get";e.useFullLoading=!!c;e.data=a.serialize();b.appRequests().getActionCall(e,function(c){b.msg.out(c);0!==c.status?a.find(":input[name=h]").val(""):(void 0!==d&&d.close(),
-setTimeout(function(){b.redirect("index.php")},5E3))})}}})},getUpdates:function(){e.info("main:getUpdates");var a=b.appRequests().getRequestOpts();a.url=f.entrypoint+"?r=status/checkRelease";a.method="get";a.timeout=1E4;a.useLoading=!1;a.data={isAjax:1};var c=$("#updates");b.appRequests().getActionCall(a,function(a){0===a.status?0'+a.data.title+'cloud_download
'+
+"
";mdlDialog().show({text:c,negative:{title:b.config().LANG[44],onClick:function(a){a.preventDefault();b.msg.error(b.config().LANG[44])}},positive:{title:b.config().LANG[43],onClick:function(c){var d;(c=a.find("input[name='taskId']").val())&&(d=t(c));var e=b.appRequests().getRequestOpts();e.url=f.entrypoint+"?r="+a.data("action-route");e.method="get";e.useFullLoading=!!c;e.data=a.serialize();b.appRequests().getActionCall(e,function(c){b.msg.out(c);0!==c.status?a.find(":input[name=key]").val(""):
+(void 0!==d&&d.close(),setTimeout(function(){b.redirect("index.php")},5E3))})}}})},getUpdates:function(){e.info("main:getUpdates");var a=b.appRequests().getRequestOpts();a.url=f.entrypoint+"?r=status/checkRelease";a.method="get";a.timeout=1E4;a.useLoading=!1;a.data={isAjax:1};var c=$("#updates");b.appRequests().getActionCall(a,function(a){0===a.status?0'+a.data.title+'cloud_download
'+
a.data.description+""):c.html('check_circle
'+b.config().LANG[68]+""):c.html('warning
'+b.config().LANG[69]+"");void 0!==componentHandler&&componentHandler.upgradeDom()},
function(){c.html('warning
'+b.config().LANG[69]+"")})},getNotices:function(){e.info("main:getNotices");var a=b.appRequests().getRequestOpts();a.url=f.entrypoint+"?r=status/checkNotices";a.method="get";a.timeout=1E4;a.useLoading=!1;a.data={isAjax:1};var c=$("#notices");b.appRequests().getActionCall(a,function(a){0===a.status&&0feedback
'+b.config().LANG[70]+"
"+a.data.map(function(a){return a.title}).join("
")+"");void 0!==componentHandler&&componentHandler.upgradeDom()})}},k={state:{tab:{index:0,
diff --git a/schemas/30018010101.sql b/schemas/30018010101.sql
index 8e8e1033..1ae7246d 100644
--- a/schemas/30018010101.sql
+++ b/schemas/30018010101.sql
@@ -1,75 +1,234 @@
-ALTER TABLE `customers`
- ADD `customer_isGlobal` TINYINT(1) DEFAULT '0' NULL;
-ALTER TABLE `usrData`
- ADD `user_ssoLogin` VARCHAR(100) NULL
- AFTER `user_login`;
-
-DROP INDEX IDX_login
-ON `usrData`;
-CREATE UNIQUE INDEX `IDX_login`
- ON `usrData` (`user_login`, `user_ssoLogin`);
-
-ALTER TABLE plugins
- ADD `plugin_available` TINYINT(1) DEFAULT '0' NULL;
-
-ALTER TABLE `customFieldsDef`
- CHANGE COLUMN `customfielddef_field` `customfielddef_field` BLOB NULL;
-ALTER TABLE customFieldsDef
- ADD `required` TINYINT(1) UNSIGNED NULL;
-ALTER TABLE customFieldsDef
- ADD `help` VARCHAR(255) NULL;
-ALTER TABLE customFieldsDef
- ADD `showInList` TINYINT(1) UNSIGNED NULL;
-ALTER TABLE customFieldsDef
- ADD `name` VARCHAR(100) NOT NULL
- AFTER customfielddef_id;
-ALTER TABLE customFieldsDef
- ADD `typeId` TINYINT UNSIGNED NULL;
-ALTER TABLE customFieldsDef
- CHANGE customfielddef_module moduleId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE customFieldsDef
- CHANGE customfielddef_field field BLOB NOT NULL;
-
-ALTER TABLE customFieldsData
- DROP FOREIGN KEY fk_customFieldsData_def_id;
-
-ALTER TABLE customFieldsData
- CHANGE customfielddata_defId definitionId INT(10) UNSIGNED NOT NULL;
-ALTER TABLE customFieldsDef
- CHANGE customfielddef_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE customFieldsData
- CHANGE customfielddata_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE customFieldsData
- CHANGE customfielddata_moduleId moduleId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE customFieldsData
- CHANGE customfielddata_itemId itemId INT(10) UNSIGNED NOT NULL;
-ALTER TABLE customFieldsData
- CHANGE customfielddata_data data LONGBLOB;
-ALTER TABLE customFieldsData
- CHANGE customfielddata_key `key` VARBINARY(1000);
+SET FOREIGN_KEY_CHECKS=0;
CREATE TABLE `CustomFieldType` (
`id` TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`text` VARCHAR(50) NOT NULL,
- PRIMARY KEY (`id`)
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_CustomFieldType_01` (`name`)
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8;
--- Extraer antes desde los datos
-INSERT INTO CustomFieldType (id, name, text) VALUES (1, 'text', 'Texto');
-INSERT INTO CustomFieldType (id, name, text) VALUES (2, 'password', 'Clave');
-INSERT INTO CustomFieldType (id, name, text) VALUES (3, 'date', 'Fecha');
-INSERT INTO CustomFieldType (id, name, text) VALUES (4, 'number', 'Número');
-INSERT INTO CustomFieldType (id, name, text) VALUES (5, 'email', 'Email');
-INSERT INTO CustomFieldType (id, name, text) VALUES (6, 'telephone', 'Teléfono');
-INSERT INTO CustomFieldType (id, name, text) VALUES (7, 'url', 'URL');
-INSERT INTO CustomFieldType (id, name, text) VALUES (8, 'color', 'Color');
-INSERT INTO CustomFieldType (id, name, text) VALUES (9, 'wiki', 'Wiki');
-INSERT INTO CustomFieldType (id, name, text) VALUES (10, 'textarea', 'Área de texto');
+INSERT INTO CustomFieldType (id, name, text)
+VALUES (1, 'text', 'Texto'), (2, 'password', 'Clave'), (3, 'date', 'Fecha'), (4, 'number', 'Número'),
+ (5, 'email', 'Email'), (6, 'telephone', 'Teléfono'), (7, 'url', 'URL'), (8, 'color', 'Color'), (9, 'wiki', 'Wiki'),
+ (10, 'textarea', 'Área de texto');
-ALTER TABLE `publicLinks`
+-- Foreign Keys;
+ALTER TABLE accFavorites
+ DROP FOREIGN KEY `fk_accFavorites_users_id`,
+ DROP FOREIGN KEY `fk_accFavorites_accounts_id`;
+
+ALTER TABLE accHistory
+ DROP FOREIGN KEY fk_accHistory_userGroup_id,
+ DROP FOREIGN KEY fk_accHistory_users_id,
+ DROP FOREIGN KEY fk_accHistory_users_edit_id,
+ DROP FOREIGN KEY fk_accHistory_customer_id,
+ DROP FOREIGN KEY fk_accHistory_category_id;
+
+ALTER TABLE usrData
+ DROP FOREIGN KEY fk_usrData_profiles_id,
+ DROP FOREIGN KEY fk_usrData_groups_id,
+ DROP INDEX fk_usrData_groups_id_idx,
+ DROP INDEX fk_usrData_profiles_id_idx;
+
+ALTER TABLE accounts
+ DROP FOREIGN KEY fk_accounts_userGroup_id,
+ DROP FOREIGN KEY fk_accounts_user_id,
+ DROP FOREIGN KEY fk_accounts_user_edit_id,
+ DROP FOREIGN KEY fk_accounts_customer_id,
+ DROP FOREIGN KEY fk_accounts_category_id,
+ DROP INDEX fk_accounts_user_id,
+ DROP INDEX fk_accounts_user_edit_id;
+
+ALTER TABLE accTags
+ DROP FOREIGN KEY fk_accTags_accounts_id,
+ DROP FOREIGN KEY fk_accTags_tags_id,
+ DROP INDEX IDX_id,
+ DROP INDEX fk_accTags_tags_id_idx;
+
+ALTER TABLE accUsers
+ DROP FOREIGN KEY fk_accUsers_accounts_id,
+ DROP FOREIGN KEY fk_accUsers_users_id,
+ DROP INDEX fk_accUsers_users_id_idx;
+
+ALTER TABLE accGroups
+ DROP FOREIGN KEY fk_accGroups_accounts_id,
+ DROP FOREIGN KEY fk_accGroups_groups_id,
+ DROP INDEX fk_accGroups_groups_id_idx;
+
+ALTER TABLE accHistory
+ DROP INDEX fk_accHistory_userGroup_id,
+ DROP INDEX fk_accHistory_users_id,
+ DROP INDEX fk_accHistory_users_edit_id_idx,
+ DROP INDEX fk_accHistory_customers_id,
+ DROP INDEX fk_accHistory_categories_id;
+
+ALTER TABLE accFiles
+ DROP FOREIGN KEY fk_accFiles_accounts_id;
+
+ALTER TABLE authTokens
+ DROP FOREIGN KEY fk_authTokens_user_id,
+ DROP FOREIGN KEY fk_authTokens_createdBy_id,
+ DROP INDEX fk_authTokens_users_id_idx,
+ DROP INDEX fk_authTokens_users_createdby_id;
+
+ALTER TABLE usrPassRecover
+ DROP FOREIGN KEY fk_usrPassRecover_users;
+
+ALTER TABLE usrToGroups
+ DROP FOREIGN KEY fk_usrToGroups_groups_id,
+ DROP FOREIGN KEY fk_usrToGroups_users_id,
+ DROP INDEX fk_usrToGroups_groups_id_idx;
+
+ALTER TABLE customFieldsData
+ DROP FOREIGN KEY fk_customFieldsData_def_id;
+
+-- CustomFieldData;
+ALTER TABLE customFieldsData
+ CHANGE customfielddata_defId definitionId INT(10) UNSIGNED NOT NULL,
+ CHANGE customfielddata_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE customfielddata_moduleId moduleId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE customfielddata_itemId itemId INT(10) UNSIGNED NOT NULL,
+ CHANGE customfielddata_data data LONGBLOB,
+ CHANGE customfielddata_key `key` VARBINARY(1000),
+ DROP INDEX IDX_DEFID,
+ ADD INDEX idx_CustomFieldData_01 (definitionId ASC),
+ DROP INDEX IDX_DELETE,
+ ADD INDEX idx_CustomFieldData_02 (itemId ASC, moduleId ASC),
+ DROP INDEX IDX_UPDATE,
+ DROP INDEX IDX_MODULE,
+ ADD INDEX idx_CustomFieldData_03 (moduleId ASC),
+ ADD INDEX uk_CustomFieldData_01 (moduleId ASC, itemId ASC, definitionId ASC),
+ DROP INDEX IDX_ITEM,
+RENAME TO CustomFieldData;
+
+-- CustomFieldDefinition;
+ALTER TABLE customFieldsDef
+ ADD required TINYINT(1) UNSIGNED NULL,
+ ADD help VARCHAR(255) NULL,
+ ADD showInList TINYINT(1) UNSIGNED NULL,
+ ADD name VARCHAR(100) NOT NULL
+ AFTER id,
+ ADD typeId TINYINT UNSIGNED NOT NULL,
+ CHANGE customfielddef_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE customfielddef_module moduleId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE customfielddef_field field BLOB NULL,
+RENAME TO CustomFieldDefinition;
+
+-- EventLog;
+ALTER TABLE log
+ CHANGE log_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE log_date date INT(10) UNSIGNED NOT NULL,
+ CHANGE log_login login VARCHAR(25),
+ CHANGE log_userId userId SMALLINT(5) UNSIGNED,
+ CHANGE log_ipAddress ipAddress VARCHAR(45) NOT NULL,
+ CHANGE log_action action VARCHAR(50) NOT NULL,
+ CHANGE log_description description TEXT,
+ CHANGE log_level level VARCHAR(20) NOT NULL,
+ DROP INDEX `fk_log_users_id_idx`,
+RENAME TO EventLog;
+
+-- Track;
+ALTER TABLE track
+ CHANGE track_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE track_userId userId SMALLINT(5) UNSIGNED,
+ CHANGE track_source source VARCHAR(100) NOT NULL,
+ CHANGE track_time time INT(10) UNSIGNED NOT NULL,
+ CHANGE track_ipv4 ipv4 BINARY(4) NOT NULL,
+ CHANGE track_ipv6 ipv6 BINARY(16),
+ DROP INDEX IDX_userId,
+ ADD INDEX idx_Track_01 (userId ASC),
+ DROP INDEX `IDX_time-ip-source`,
+ ADD INDEX `idx_Track_02` (time ASC, ipv4 ASC, ipv6 ASC, source ASC),
+RENAME TO Track;
+
+-- AccountFile;
+ALTER TABLE accFiles
+ CHANGE accfile_accountId accountId MEDIUMINT(5) UNSIGNED NOT NULL,
+ CHANGE accfile_id id INT(11) NOT NULL AUTO_INCREMENT,
+ CHANGE accfile_name name VARCHAR(100) NOT NULL,
+ CHANGE accfile_type type VARCHAR(100) NOT NULL,
+ CHANGE accfile_size size INT(11) NOT NULL,
+ CHANGE accfile_content content MEDIUMBLOB NOT NULL,
+ CHANGE accfile_extension extension VARCHAR(10) NOT NULL,
+ CHANGE accFile_thumb thumb MEDIUMBLOB,
+ DROP INDEX IDX_accountId,
+ ADD INDEX idx_AccountFile_01 (accountId ASC),
+RENAME TO AccountFile;
+
+-- User;
+ALTER TABLE usrData
+ DROP user_secGroupId,
+ CHANGE user_id id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE user_name name VARCHAR(80) NOT NULL,
+ CHANGE user_groupId userGroupId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE user_login login VARCHAR(50) NOT NULL,
+ ADD ssoLogin VARCHAR(100) NULL
+ AFTER login,
+ CHANGE user_pass pass VARBINARY(1000) NOT NULL,
+ CHANGE user_mPass mPass VARBINARY(1000) DEFAULT NULL,
+ CHANGE user_mKey mKey VARBINARY(1000) DEFAULT NULL,
+ CHANGE user_email email VARCHAR(80),
+ CHANGE user_notes notes TEXT,
+ CHANGE user_count loginCount INT(10) UNSIGNED NOT NULL DEFAULT '0',
+ CHANGE user_profileId userProfileId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE user_lastLogin lastLogin DATETIME,
+ CHANGE user_lastUpdate lastUpdate DATETIME,
+ CHANGE user_lastUpdateMPass lastUpdateMPass INT(11) UNSIGNED NOT NULL DEFAULT '0',
+ CHANGE user_isAdminApp isAdminApp TINYINT(1) DEFAULT 0,
+ CHANGE user_isAdminAcc isAdminAcc TINYINT(1) DEFAULT 0,
+ CHANGE user_isLdap isLdap TINYINT(1) DEFAULT 0,
+ CHANGE user_isDisabled isDisabled TINYINT(1) DEFAULT 0,
+ CHANGE user_hashSalt hashSalt VARBINARY(128) NOT NULL,
+ CHANGE user_isMigrate isMigrate TINYINT(1) DEFAULT 0,
+ CHANGE user_isChangePass isChangePass TINYINT(1) DEFAULT 0,
+ CHANGE user_isChangedPass isChangedPass TINYINT(1) DEFAULT 0,
+ CHANGE user_preferences preferences BLOB,
+ DROP INDEX IDX_pass,
+ ADD INDEX idx_User_01 (pass ASC),
+ DROP INDEX IDX_login,
+ ADD UNIQUE INDEX `uk_User_01` (`login`, `ssoLogin`),
+RENAME TO User;
+
+-- UserProfile;
+ALTER TABLE usrProfiles
+ CHANGE userprofile_id id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE userprofile_name name VARCHAR(45) NOT NULL,
+ CHANGE userProfile_profile profile BLOB NOT NULL,
+RENAME TO UserProfile;
+
+-- Notice;
+ALTER TABLE notices
+ CHANGE notice_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE notice_type type VARCHAR(100),
+ CHANGE notice_component component VARCHAR(100) NOT NULL,
+ CHANGE notice_description description VARCHAR(500) NOT NULL,
+ CHANGE notice_date date INT(10) UNSIGNED NOT NULL,
+ CHANGE notice_checked checked TINYINT(1) DEFAULT 0,
+ CHANGE notice_userId userId SMALLINT(5) UNSIGNED,
+ CHANGE notice_sticky sticky TINYINT(1) DEFAULT 0,
+ CHANGE notice_onlyAdmin onlyAdmin TINYINT(1) DEFAULT 0,
+ DROP INDEX IDX_userId,
+ ADD INDEX idx_Notification_01 (userId ASC, checked ASC, date ASC),
+ DROP INDEX IDX_component,
+ ADD INDEX idx_Notification_02 (component ASC, date ASC, checked ASC, userId ASC),
+RENAME TO Notification;
+
+-- Plugin;
+ALTER TABLE plugins
+ CHANGE plugin_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE plugin_name name VARCHAR(100) NOT NULL,
+ CHANGE plugin_data data VARBINARY(5000),
+ CHANGE plugin_enabled enabled TINYINT(1) NOT NULL DEFAULT 0,
+ ADD available TINYINT(1) DEFAULT 0,
+ DROP INDEX plugin_name_UNIQUE,
+ ADD UNIQUE INDEX uk_Plugin_01 (name ASC),
+RENAME TO Plugin;
+
+-- PublicLink;
+ALTER TABLE publicLinks
ADD COLUMN `userId` SMALLINT(5) UNSIGNED NOT NULL,
ADD COLUMN `typeId` INT(10) UNSIGNED NOT NULL
AFTER `userId`,
@@ -88,521 +247,204 @@ ALTER TABLE `publicLinks`
ADD COLUMN `maxCountViews` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0
AFTER `totalCountViews`,
ADD COLUMN `useinfo` BLOB NULL
- AFTER `maxCountViews`;
-
--- Foreign Keys
-ALTER TABLE accHistory
- DROP FOREIGN KEY fk_accHistory_userGroup_id;
-ALTER TABLE accHistory
- DROP FOREIGN KEY fk_accHistory_users_id;
-ALTER TABLE accHistory
- DROP FOREIGN KEY fk_accHistory_users_edit_id;
-ALTER TABLE accHistory
- DROP FOREIGN KEY fk_accHistory_customer_id;
-ALTER TABLE accHistory
- DROP FOREIGN KEY fk_accHistory_category_id;
-
-ALTER TABLE usrData
- DROP FOREIGN KEY fk_usrData_profiles_id;
-ALTER TABLE usrData
- DROP FOREIGN KEY fk_usrData_groups_id;
-DROP INDEX fk_usrData_groups_id_idx
-ON usrData;
-DROP INDEX fk_usrData_profiles_id_idx
-ON usrData;
-
-ALTER TABLE accounts
- DROP FOREIGN KEY fk_accounts_userGroup_id;
-ALTER TABLE accounts
- DROP FOREIGN KEY fk_accounts_user_id;
-ALTER TABLE accounts
- DROP FOREIGN KEY fk_accounts_user_edit_id;
-ALTER TABLE accounts
- DROP FOREIGN KEY fk_accounts_customer_id;
-ALTER TABLE accounts
- DROP FOREIGN KEY fk_accounts_category_id;
-DROP INDEX fk_accounts_user_id
-ON accounts;
-DROP INDEX fk_accounts_user_edit_id
-ON accounts;
-
-ALTER TABLE accTags
- DROP FOREIGN KEY fk_accTags_accounts_id;
-ALTER TABLE accTags
- DROP FOREIGN KEY fk_accTags_tags_id;
-DROP INDEX IDX_id
-ON accTags;
-DROP INDEX fk_accTags_tags_id_idx
-ON accTags;
-
-ALTER TABLE accUsers
- DROP FOREIGN KEY fk_accUsers_accounts_id;
-ALTER TABLE accUsers
- DROP FOREIGN KEY fk_accUsers_users_id;
-DROP INDEX fk_accUsers_users_id_idx
-ON accUsers;
-
-ALTER TABLE accGroups
- DROP FOREIGN KEY fk_accGroups_accounts_id;
-ALTER TABLE accGroups
- DROP FOREIGN KEY fk_accGroups_groups_id;
-DROP INDEX fk_accGroups_groups_id_idx
-ON accGroups;
-
-DROP INDEX fk_accHistory_userGroup_id
-ON accHistory;
-DROP INDEX fk_accHistory_users_id
-ON accHistory;
-DROP INDEX fk_accHistory_users_edit_id_idx
-ON accHistory;
-DROP INDEX fk_accHistory_customers_id
-ON accHistory;
-DROP INDEX fk_accHistory_categories_id
-ON accHistory;
-
-ALTER TABLE accFiles
- DROP FOREIGN KEY fk_accFiles_accounts_id;
-
-ALTER TABLE authTokens
- DROP FOREIGN KEY fk_authTokens_user_id;
-ALTER TABLE authTokens
- DROP FOREIGN KEY fk_authTokens_createdBy_id;
-DROP INDEX fk_authTokens_users_id_idx
-ON authTokens;
-DROP INDEX fk_authTokens_users_createdby_id
-ON authTokens;
-
-ALTER TABLE usrPassRecover
- DROP FOREIGN KEY fk_usrPassRecover_users;
-
-ALTER TABLE usrToGroups
- DROP FOREIGN KEY fk_usrToGroups_groups_id;
-ALTER TABLE usrToGroups
- DROP FOREIGN KEY fk_usrToGroups_users_id;
-DROP INDEX fk_usrToGroups_groups_id_idx
-ON usrToGroups;
-
--- CustomFieldData
-ALTER TABLE customFieldsData
-RENAME TO CustomFieldData;
-
--- CustomFieldDefinition
-ALTER TABLE customFieldsDef
-RENAME TO CustomFieldDefinition;
-
--- EventLog
-ALTER TABLE log
- CHANGE log_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE log
- CHANGE log_date date INT(10) UNSIGNED NOT NULL;
-ALTER TABLE log
- CHANGE log_login login VARCHAR(25);
-ALTER TABLE log
- CHANGE log_userId userId SMALLINT(5) UNSIGNED;
-ALTER TABLE log
- CHANGE log_ipAddress ipAddress VARCHAR(45) NOT NULL;
-ALTER TABLE log
- CHANGE log_action action VARCHAR(50) NOT NULL;
-ALTER TABLE log
- CHANGE log_description description TEXT;
-ALTER TABLE log
- CHANGE log_level level VARCHAR(20) NOT NULL;
-ALTER TABLE log
-RENAME TO EventLog;
-
--- Track
-ALTER TABLE track
- CHANGE track_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE track
- CHANGE track_userId userId SMALLINT(5) UNSIGNED;
-ALTER TABLE track
- CHANGE track_source source VARCHAR(100) NOT NULL;
-ALTER TABLE track
- CHANGE track_time time INT(10) UNSIGNED NOT NULL;
-ALTER TABLE track
- CHANGE track_ipv4 ipv4 BINARY(4) NOT NULL;
-ALTER TABLE track
- CHANGE track_ipv6 ipv6 BINARY(16);
-ALTER TABLE track
-RENAME TO Track;
-
--- AccountFile
-ALTER TABLE accFiles
- CHANGE accfile_accountId accountId MEDIUMINT(5) UNSIGNED NOT NULL;
-ALTER TABLE accFiles
- CHANGE accfile_id id INT(11) NOT NULL AUTO_INCREMENT;
-ALTER TABLE accFiles
- CHANGE accfile_name name VARCHAR(100) NOT NULL;
-ALTER TABLE accFiles
- CHANGE accfile_type type VARCHAR(100) NOT NULL;
-ALTER TABLE accFiles
- CHANGE accfile_size size INT(11) NOT NULL;
-ALTER TABLE accFiles
- CHANGE accfile_content content MEDIUMBLOB NOT NULL;
-ALTER TABLE accFiles
- CHANGE accfile_extension extension VARCHAR(10) NOT NULL;
-ALTER TABLE accFiles
- CHANGE accFile_thumb thumb MEDIUMBLOB;
-ALTER TABLE accFiles
-RENAME TO AccountFile;
-
--- User
-ALTER TABLE usrData
- DROP user_secGroupId;
-ALTER TABLE usrData
- CHANGE user_id id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE usrData
- CHANGE user_name name VARCHAR(80) NOT NULL;
-ALTER TABLE usrData
- CHANGE user_groupId userGroupId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE usrData
- CHANGE user_login login VARCHAR(50) NOT NULL;
-ALTER TABLE usrData
- CHANGE user_ssoLogin ssoLogin VARCHAR(100);
-ALTER TABLE usrData
- CHANGE user_pass pass VARBINARY(1000) NOT NULL;
-ALTER TABLE usrData
- CHANGE user_mPass mPass VARBINARY(1000) DEFAULT NULL;
-ALTER TABLE usrData
- CHANGE user_mKey mKey VARBINARY(1000) DEFAULT NULL;
-ALTER TABLE usrData
- CHANGE user_email email VARCHAR(80);
-ALTER TABLE usrData
- CHANGE user_notes notes TEXT;
-ALTER TABLE usrData
- CHANGE user_count loginCount INT(10) UNSIGNED NOT NULL DEFAULT '0';
-ALTER TABLE usrData
- CHANGE user_profileId userProfileId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE usrData
- CHANGE user_lastLogin lastLogin DATETIME;
-ALTER TABLE usrData
- CHANGE user_lastUpdate lastUpdate DATETIME;
-ALTER TABLE usrData
- CHANGE user_lastUpdateMPass lastUpdateMPass INT(11) UNSIGNED NOT NULL DEFAULT '0';
-ALTER TABLE usrData
- CHANGE user_isAdminApp isAdminApp TINYINT(1) DEFAULT 0;
-ALTER TABLE usrData
- CHANGE user_isAdminAcc isAdminAcc TINYINT(1) DEFAULT 0;
-ALTER TABLE usrData
- CHANGE user_isLdap isLdap TINYINT(1) DEFAULT 0;
-ALTER TABLE usrData
- CHANGE user_isDisabled isDisabled TINYINT(1) DEFAULT 0;
-ALTER TABLE usrData
- CHANGE user_hashSalt hashSalt VARBINARY(128) NOT NULL;
-ALTER TABLE usrData
- CHANGE user_isMigrate isMigrate TINYINT(1) DEFAULT 0;
-ALTER TABLE usrData
- CHANGE user_isChangePass isChangePass TINYINT(1) DEFAULT 0;
-ALTER TABLE usrData
- CHANGE user_isChangedPass isChangedPass TINYINT(1) DEFAULT 0;
-ALTER TABLE usrData
- CHANGE user_preferences preferences BLOB;
-ALTER TABLE usrData
-RENAME TO User;
-
--- UserProfile
-ALTER TABLE usrProfiles
- CHANGE userprofile_id id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE usrProfiles
- CHANGE userprofile_name name VARCHAR(45) NOT NULL;
-ALTER TABLE usrProfiles
- CHANGE userProfile_profile profile BLOB NOT NULL;
-ALTER TABLE usrProfiles
-RENAME TO UserProfile;
-
--- Notice
-ALTER TABLE notices
- CHANGE notice_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE notices
- CHANGE notice_type type VARCHAR(100);
-ALTER TABLE notices
- CHANGE notice_component component VARCHAR(100) NOT NULL;
-ALTER TABLE notices
- CHANGE notice_description description VARCHAR(500) NOT NULL;
-ALTER TABLE notices
- CHANGE notice_date date INT(10) UNSIGNED NOT NULL;
-ALTER TABLE notices
- CHANGE notice_checked checked TINYINT(1) DEFAULT 0;
-ALTER TABLE notices
- CHANGE notice_userId userId SMALLINT(5) UNSIGNED;
-ALTER TABLE notices
- CHANGE notice_sticky sticky TINYINT(1) DEFAULT 0;
-ALTER TABLE notices
- CHANGE notice_onlyAdmin onlyAdmin TINYINT(1) DEFAULT 0;
-ALTER TABLE notices
-RENAME TO Notification;
-
--- Plugin
-ALTER TABLE plugins
- CHANGE plugin_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE plugins
- CHANGE plugin_name name VARCHAR(100) NOT NULL;
-ALTER TABLE plugins
- CHANGE plugin_data data VARBINARY(5000);
-ALTER TABLE plugins
- CHANGE plugin_enabled enabled TINYINT(1) NOT NULL DEFAULT 0;
-ALTER TABLE plugins
- CHANGE plugin_available available TINYINT(1) DEFAULT 0;
-ALTER TABLE plugins
-RENAME TO Plugin;
-
--- PublicLink
-ALTER TABLE publicLinks
- CHANGE publicLink_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE publicLinks
- CHANGE publicLink_itemId itemId INT(10) UNSIGNED NOT NULL;
-ALTER TABLE publicLinks
- CHANGE publicLink_hash hash VARBINARY(100) NOT NULL;
-ALTER TABLE publicLinks
- CHANGE publicLink_linkData data LONGBLOB;
-ALTER TABLE publicLinks
+ AFTER `maxCountViews`,
+ CHANGE publicLink_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE publicLink_itemId itemId INT(10) UNSIGNED NOT NULL,
+ CHANGE publicLink_hash `hash` VARBINARY(100) NOT NULL,
+ CHANGE publicLink_linkData `data` LONGBLOB,
+ DROP INDEX IDX_hash,
+ ADD UNIQUE INDEX uk_PublicLink_01 (`hash` ASC),
+ DROP INDEX unique_publicLink_accountId,
+ ADD UNIQUE INDEX uk_PublicLink_02 (itemId ASC),
+ DROP INDEX IDX_itemId,
+ DROP INDEX unique_publicLink_hash,
RENAME TO PublicLink;
--- Category
-ALTER TABLE categories
- CHANGE category_id id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE categories
- CHANGE category_name name VARCHAR(50) NOT NULL;
-ALTER TABLE categories
- CHANGE category_hash hash VARBINARY(40) NOT NULL;
-ALTER TABLE categories
- CHANGE category_description description VARCHAR(255);
+-- Category;
ALTER TABLE categories
+ CHANGE category_id id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE category_name name VARCHAR(50) NOT NULL,
+ CHANGE category_hash hash VARBINARY(40) NOT NULL,
+ CHANGE category_description description VARCHAR(255),
+ ADD UNIQUE INDEX uk_Category_01 (`hash` ASC),
RENAME TO Category;
--- Config
-DROP INDEX vacParameter
-ON config;
-ALTER TABLE config
- CHANGE config_parameter parameter VARCHAR(50) NOT NULL;
-ALTER TABLE config
- CHANGE config_value value VARCHAR(4000);
-ALTER TABLE config
- ADD PRIMARY KEY (parameter);
+-- Config;
ALTER TABLE config
+ CHANGE config_parameter parameter VARCHAR(50) NOT NULL,
+ CHANGE config_value VALUE VARCHAR(4000),
+ DROP INDEX vacParameter,
+ ADD PRIMARY KEY (parameter),
RENAME TO Config;
--- Customer
-ALTER TABLE customers
- CHANGE customer_id id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE customers
- CHANGE customer_name name VARCHAR(100) NOT NULL;
-ALTER TABLE customers
- CHANGE customer_hash hash VARBINARY(40) NOT NULL;
-ALTER TABLE customers
- CHANGE customer_description description VARCHAR(255);
-ALTER TABLE customers
- CHANGE customer_isGlobal isGlobal TINYINT(1) DEFAULT 0;
+-- Customer;
ALTER TABLE customers
+ CHANGE customer_id id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE customer_name name VARCHAR(100) NOT NULL,
+ CHANGE customer_hash hash VARBINARY(40) NOT NULL,
+ CHANGE customer_description description VARCHAR(255),
+ ADD `isGlobal` TINYINT(1) DEFAULT 0,
+ ADD INDEX uk_Client_01 (`hash` ASC),
+ DROP INDEX IDX_name,
RENAME TO Client;
--- Account
-ALTER TABLE accounts
- CHANGE account_id id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE accounts
- CHANGE account_userGroupId userGroupId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE accounts
- CHANGE account_userId userId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE accounts
- CHANGE account_userEditId userEditId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE accounts
- CHANGE account_customerId clientId MEDIUMINT(8) UNSIGNED NOT NULL;
-ALTER TABLE accounts
- CHANGE account_name name VARCHAR(50) NOT NULL;
-ALTER TABLE accounts
- CHANGE account_categoryId categoryId MEDIUMINT UNSIGNED NOT NULL;
-ALTER TABLE accounts
- CHANGE account_login login VARCHAR(50);
-ALTER TABLE accounts
- CHANGE account_url url VARCHAR(255);
-ALTER TABLE accounts
- CHANGE account_pass pass VARBINARY(1000) NOT NULL;
-ALTER TABLE accounts
- CHANGE account_key `key` VARBINARY(1000) NOT NULL;
-ALTER TABLE accounts
- CHANGE account_notes notes TEXT;
-ALTER TABLE accounts
- CHANGE account_countView countView INT(10) UNSIGNED NOT NULL DEFAULT '0';
-ALTER TABLE accounts
- CHANGE account_countDecrypt countDecrypt INT(10) UNSIGNED NOT NULL DEFAULT '0';
-ALTER TABLE accounts
- CHANGE account_dateAdd dateAdd DATETIME NOT NULL;
-ALTER TABLE accounts
- CHANGE account_dateEdit dateEdit DATETIME;
-ALTER TABLE accounts
- CHANGE account_otherGroupEdit otherUserGroupEdit TINYINT(1) DEFAULT 0;
-ALTER TABLE accounts
- CHANGE account_otherUserEdit otherUserEdit TINYINT(1) DEFAULT 0;
-ALTER TABLE accounts
- CHANGE account_isPrivate isPrivate TINYINT(1) DEFAULT 0;
-ALTER TABLE accounts
- CHANGE account_isPrivateGroup isPrivateGroup TINYINT(1) DEFAULT 0;
-ALTER TABLE accounts
- CHANGE account_passDate passDate INT(11) UNSIGNED;
-ALTER TABLE accounts
- CHANGE account_passDateChange passDateChange INT(11) UNSIGNED;
-ALTER TABLE accounts
- CHANGE account_parentId parentId MEDIUMINT UNSIGNED;
+-- Account;
ALTER TABLE accounts
+ CHANGE account_id id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE account_userGroupId userGroupId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE account_userId userId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE account_userEditId userEditId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE account_customerId clientId MEDIUMINT(8) UNSIGNED NOT NULL,
+ CHANGE account_name name VARCHAR(50) NOT NULL,
+ CHANGE account_categoryId categoryId MEDIUMINT UNSIGNED NOT NULL,
+ CHANGE account_login login VARCHAR(50),
+ CHANGE account_url url VARCHAR(255),
+ CHANGE account_pass pass VARBINARY(1000) NOT NULL,
+ CHANGE account_key `key` VARBINARY(1000) NOT NULL,
+ CHANGE account_notes notes TEXT,
+ CHANGE account_countView countView INT(10) UNSIGNED NOT NULL DEFAULT 0,
+ CHANGE account_countDecrypt countDecrypt INT(10) UNSIGNED NOT NULL DEFAULT 0,
+ CHANGE account_dateAdd dateAdd DATETIME NOT NULL,
+ CHANGE account_dateEdit dateEdit DATETIME,
+ CHANGE account_otherGroupEdit otherUserGroupEdit TINYINT(1) DEFAULT 0,
+ CHANGE account_otherUserEdit otherUserEdit TINYINT(1) DEFAULT 0,
+ CHANGE account_isPrivate isPrivate TINYINT(1) DEFAULT 0,
+ CHANGE account_isPrivateGroup isPrivateGroup TINYINT(1) DEFAULT 0,
+ CHANGE account_passDate passDate INT(11) UNSIGNED,
+ CHANGE account_passDateChange passDateChange INT(11) UNSIGNED,
+ CHANGE account_parentId parentId MEDIUMINT UNSIGNED,
+ DROP INDEX IDX_categoryId,
+ ADD INDEX idx_Account_01 (`categoryId` ASC),
+ DROP INDEX IDX_userId,
+ ADD INDEX idx_Account_02 (`userGroupId` ASC, `userId` ASC),
+ DROP INDEX IDX_customerId,
+ ADD INDEX idx_Account_03 (`clientId` ASC),
+ DROP INDEX account_parentId,
+ ADD INDEX idx_Account_04 (`parentId` ASC),
+ DROP INDEX IDX_parentId,
RENAME TO Account;
--- AccountToFavorite
-DROP INDEX fk_accFavorites_users_idx
-ON accFavorites;
-DROP INDEX fk_accFavorites_accounts_idx
-ON accFavorites;
-ALTER TABLE accFavorites
- CHANGE accfavorite_accountId accountId MEDIUMINT UNSIGNED NOT NULL;
-ALTER TABLE accFavorites
- CHANGE accfavorite_userId userId SMALLINT(5) UNSIGNED NOT NULL;
+-- AccountToFavorite;
ALTER TABLE accFavorites
+ DROP INDEX fk_accFavorites_users_idx,
+ DROP INDEX fk_accFavorites_accounts_idx,
+ CHANGE accfavorite_accountId accountId MEDIUMINT UNSIGNED NOT NULL,
+ CHANGE accfavorite_userId userId SMALLINT(5) UNSIGNED NOT NULL,
+ DROP INDEX search_idx,
+ ADD INDEX idx_AccountToFavorite_01 (accountId ASC, userId ASC),
RENAME TO AccountToFavorite;
--- AccountHistory
-ALTER TABLE accHistory
- CHANGE acchistory_id id INT(11) NOT NULL AUTO_INCREMENT;
-ALTER TABLE accHistory
- CHANGE acchistory_accountId accountId MEDIUMINT UNSIGNED NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_userGroupId userGroupId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_userId userId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_userEditId userEditId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_customerId clientId MEDIUMINT UNSIGNED NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_name name VARCHAR(255) NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_categoryId categoryId MEDIUMINT UNSIGNED NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_login login VARCHAR(50);
-ALTER TABLE accHistory
- CHANGE acchistory_url url VARCHAR(255);
-ALTER TABLE accHistory
- CHANGE acchistory_pass pass VARBINARY(1000) NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_key `key` VARBINARY(1000) NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_notes notes TEXT NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_countView countView INT(10) UNSIGNED NOT NULL DEFAULT '0';
-ALTER TABLE accHistory
- CHANGE acchistory_countDecrypt countDecrypt INT(10) UNSIGNED NOT NULL DEFAULT '0';
-ALTER TABLE accHistory
- CHANGE acchistory_dateAdd dateAdd DATETIME NOT NULL;
-ALTER TABLE accHistory
- CHANGE acchistory_dateEdit dateEdit DATETIME;
-ALTER TABLE accHistory
- CHANGE acchistory_isModify isModify TINYINT(1) DEFAULT 0;
-ALTER TABLE accHistory
- CHANGE acchistory_isDeleted isDeleted TINYINT(1) DEFAULT 0;
-ALTER TABLE accHistory
- CHANGE acchistory_mPassHash mPassHash VARBINARY(255) NOT NULL;
-ALTER TABLE accHistory
- CHANGE accHistory_otherUserEdit otherUserEdit TINYINT(1) DEFAULT 0;
-ALTER TABLE accHistory
- CHANGE accHistory_otherGroupEdit otherUserGroupEdit TINYINT(1) DEFAULT 0;
-ALTER TABLE accHistory
- CHANGE accHistory_passDate passDate INT(10) UNSIGNED;
-ALTER TABLE accHistory
- CHANGE accHistory_passDateChange passDateChange INT(10) UNSIGNED;
-ALTER TABLE accHistory
- CHANGE accHistory_parentId parentId MEDIUMINT UNSIGNED;
-ALTER TABLE accHistory
- CHANGE accHistory_isPrivate isPrivate TINYINT(1) DEFAULT 0;
-ALTER TABLE accHistory
- CHANGE accHistory_isPrivateGroup isPrivateGroup TINYINT(1) DEFAULT 0;
+-- AccountHistory;
ALTER TABLE accHistory
+ CHANGE acchistory_id id INT(11) NOT NULL AUTO_INCREMENT,
+ CHANGE acchistory_accountId accountId MEDIUMINT UNSIGNED NOT NULL,
+ CHANGE acchistory_userGroupId userGroupId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE acchistory_userId userId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE acchistory_userEditId userEditId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE acchistory_customerId clientId MEDIUMINT UNSIGNED NOT NULL,
+ CHANGE acchistory_name name VARCHAR(255) NOT NULL,
+ CHANGE acchistory_categoryId categoryId MEDIUMINT UNSIGNED NOT NULL,
+ CHANGE acchistory_login login VARCHAR(50),
+ CHANGE acchistory_url url VARCHAR(255),
+ CHANGE acchistory_pass pass VARBINARY(1000) NOT NULL,
+ CHANGE acchistory_key `key` VARBINARY(1000) NOT NULL,
+ CHANGE acchistory_notes notes TEXT NOT NULL,
+ CHANGE acchistory_countView countView INT(10) UNSIGNED NOT NULL DEFAULT 0,
+ CHANGE acchistory_countDecrypt countDecrypt INT(10) UNSIGNED NOT NULL DEFAULT 0,
+ CHANGE acchistory_dateAdd dateAdd DATETIME NOT NULL,
+ CHANGE acchistory_dateEdit dateEdit DATETIME,
+ CHANGE acchistory_isModify isModify TINYINT(1) DEFAULT 0,
+ CHANGE acchistory_isDeleted isDeleted TINYINT(1) DEFAULT 0,
+ CHANGE acchistory_mPassHash mPassHash VARBINARY(255) NOT NULL,
+ CHANGE accHistory_otherUserEdit otherUserEdit TINYINT(1) DEFAULT 0,
+ CHANGE accHistory_otherGroupEdit otherUserGroupEdit TINYINT(1) DEFAULT 0,
+ CHANGE accHistory_passDate passDate INT(10) UNSIGNED,
+ CHANGE accHistory_passDateChange passDateChange INT(10) UNSIGNED,
+ CHANGE accHistory_parentId parentId MEDIUMINT UNSIGNED,
+ CHANGE accHistory_isPrivate isPrivate TINYINT(1) DEFAULT 0,
+ CHANGE accHistory_isPrivateGroup isPrivateGroup TINYINT(1) DEFAULT 0,
+ DROP INDEX IDX_accountId,
+ ADD INDEX idx_AccountHistory_01 (accountId ASC),
+ DROP INDEX acchistory_parentId,
+ ADD INDEX idx_AccountHistory_02 (parentId ASC),
RENAME TO AccountHistory;
--- Tag
-ALTER TABLE tags
- CHANGE tag_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE tags
- CHANGE tag_name name VARCHAR(45) NOT NULL;
-ALTER TABLE tags
- CHANGE tag_hash hash VARBINARY(40) NOT NULL;
+-- Tag;
ALTER TABLE tags
+ CHANGE tag_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE tag_name name VARCHAR(45) NOT NULL,
+ CHANGE tag_hash hash VARBINARY(40) NOT NULL,
+ DROP INDEX tag_hash_UNIQUE,
+ ADD UNIQUE INDEX uk_Tag_01 (`hash` ASC),
+ DROP INDEX IDX_name,
+ ADD INDEX idx_Tag_01 (`name` ASC),
RENAME TO Tag;
--- AccountToTag
-ALTER TABLE accTags
- CHANGE acctag_accountId accountId MEDIUMINT UNSIGNED NOT NULL;
-ALTER TABLE accTags
- CHANGE acctag_tagId tagId INT(10) UNSIGNED NOT NULL;
+-- AccountToTag;
ALTER TABLE accTags
+ CHANGE acctag_accountId accountId MEDIUMINT UNSIGNED NOT NULL,
+ CHANGE acctag_tagId tagId INT(10) UNSIGNED NOT NULL,
RENAME TO AccountToTag;
--- AccountToUserGroup
-ALTER TABLE accGroups
- CHANGE accgroup_accountId accountId MEDIUMINT UNSIGNED NOT NULL;
-ALTER TABLE accGroups
- CHANGE accgroup_groupId userGroupId SMALLINT(5) UNSIGNED NOT NULL;
+-- AccountToUserGroup;
ALTER TABLE accGroups
+ CHANGE accgroup_accountId accountId MEDIUMINT UNSIGNED NOT NULL,
+ CHANGE accgroup_groupId userGroupId SMALLINT(5) UNSIGNED NOT NULL,
+ DROP INDEX IDX_accountId,
+ ADD INDEX idx_AccountToUserGroup_01 (`accountId` ASC),
RENAME TO AccountToUserGroup;
--- AccountToUser
-ALTER TABLE accUsers
- CHANGE accuser_accountId accountId MEDIUMINT UNSIGNED NOT NULL;
-ALTER TABLE accUsers
- CHANGE accuser_userId userId SMALLINT(5) UNSIGNED NOT NULL;
+-- AccountToUser;
ALTER TABLE accUsers
+ CHANGE accuser_accountId accountId MEDIUMINT UNSIGNED NOT NULL,
+ CHANGE accuser_userId userId SMALLINT(5) UNSIGNED NOT NULL,
+ DROP INDEX idx_account,
+ ADD INDEX idx_AccountToUser_01 (accountId ASC),
RENAME TO AccountToUser;
--- UserToUserGroup
-ALTER TABLE usrToGroups
- CHANGE usertogroup_userId userId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE usrToGroups
- CHANGE usertogroup_groupId userGroupId SMALLINT(5) UNSIGNED NOT NULL;
+-- UserToUserGroup;
ALTER TABLE usrToGroups
+ CHANGE usertogroup_userId userId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE usertogroup_groupId userGroupId SMALLINT(5) UNSIGNED NOT NULL,
+ DROP INDEX IDX_usertogroup_userId,
+ ADD INDEX idx_UserToUserGroup_01 (userId ASC),
RENAME TO UserToUserGroup;
--- UserGroup
-ALTER TABLE usrGroups
- CHANGE usergroup_id id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE usrGroups
- CHANGE usergroup_name name VARCHAR(50) NOT NULL;
-ALTER TABLE usrGroups
- CHANGE usergroup_description description VARCHAR(255);
+-- UserGroup;
ALTER TABLE usrGroups
+ CHANGE usergroup_id id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE usergroup_name name VARCHAR(50) NOT NULL,
+ CHANGE usergroup_description description VARCHAR(255),
RENAME TO UserGroup;
--- AuthToken
-ALTER TABLE authTokens
- CHANGE authtoken_id id INT(11) NOT NULL AUTO_INCREMENT;
-ALTER TABLE authTokens
- CHANGE authtoken_userId userId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE authTokens
- CHANGE authtoken_token token VARBINARY(100) NOT NULL;
-ALTER TABLE authTokens
- CHANGE authtoken_actionId actionId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE authTokens
- CHANGE authtoken_createdBy createdBy SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE authTokens
- CHANGE authtoken_startDate startDate INT(10) UNSIGNED NOT NULL;
-ALTER TABLE authTokens
- CHANGE authtoken_vault vault VARBINARY(2000);
-ALTER TABLE authTokens
- CHANGE authtoken_hash hash VARBINARY(1000);
+-- AuthToken;
ALTER TABLE authTokens
+ CHANGE authtoken_id id INT(11) NOT NULL AUTO_INCREMENT,
+ CHANGE authtoken_userId userId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE authtoken_token token VARBINARY(100) NOT NULL,
+ CHANGE authtoken_actionId actionId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE authtoken_createdBy createdBy SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE authtoken_startDate startDate INT(10) UNSIGNED NOT NULL,
+ CHANGE authtoken_vault vault VARBINARY(2000),
+ CHANGE authtoken_hash hash VARBINARY(1000),
+ DROP INDEX unique_authtoken_id,
+ ADD UNIQUE INDEX uk_AuthToken_01 (token ASC, actionId ASC),
+ DROP INDEX IDX_checkToken,
+ ADD INDEX idx_AuthToken_01 (userId ASC, actionId ASC, token ASC),
RENAME TO AuthToken;
--- UserPassRecover
-ALTER TABLE usrPassRecover
- CHANGE userpassr_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT;
-ALTER TABLE usrPassRecover
- CHANGE userpassr_userId userId SMALLINT(5) UNSIGNED NOT NULL;
-ALTER TABLE usrPassRecover
- CHANGE userpassr_hash hash VARBINARY(128) NOT NULL;
-ALTER TABLE usrPassRecover
- CHANGE userpassr_date date INT(10) UNSIGNED NOT NULL;
-ALTER TABLE usrPassRecover
- CHANGE userpassr_used used TINYINT(1) DEFAULT 0;
+-- UserPassRecover;
ALTER TABLE usrPassRecover
+ CHANGE userpassr_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ CHANGE userpassr_userId userId SMALLINT(5) UNSIGNED NOT NULL,
+ CHANGE userpassr_hash hash VARBINARY(128) NOT NULL,
+ CHANGE userpassr_date date INT(10) UNSIGNED NOT NULL,
+ CHANGE userpassr_used used TINYINT(1) DEFAULT 0,
+ DROP INDEX IDX_userId,
+ ADD INDEX idx_UserPassRecover_01 (userId ASC, date ASC),
RENAME TO UserPassRecover;
--- Views
+-- Views;
CREATE OR REPLACE VIEW account_search_v AS
SELECT DISTINCT
`Account`.`id` AS `id`,
@@ -678,8 +520,7 @@ CREATE OR REPLACE VIEW account_data_v AS
ON ((`Account`.`clientId` = `Client`.`id`))) LEFT JOIN
`PublicLink` ON ((`Account`.`id` = `PublicLink`.`itemId`)));
--- Foreign Keys
-
+-- Foreign Keys;
CREATE INDEX fk_Account_userId
ON Account (userId);
@@ -789,6 +630,22 @@ CREATE INDEX fk_AccountToTag_accountId
CREATE INDEX fk_AccountToTag_tagId
ON AccountToTag (tagId);
+-- Fix duplicated tags;
+CREATE TEMPORARY TABLE IF NOT EXISTS tmp_tags AS (SELECT
+ accountId,
+ tagId
+ FROM AccountToTag
+ GROUP BY accountId, tagId
+ HAVING COUNT(*) > 1);
+
+DELETE a FROM AccountToTag AS a
+ INNER JOIN tmp_tags AS tmp ON tmp.accountId = a.accountId AND tmp.tagId = a.tagId;
+
+INSERT INTO AccountToTag SELECT *
+ FROM tmp_tags;
+
+DROP TEMPORARY TABLE tmp_tags;
+
ALTER TABLE AccountToTag
ADD CONSTRAINT fk_AccountToTag_accountId
FOREIGN KEY (accountId) REFERENCES Account (id)
@@ -825,6 +682,11 @@ ALTER TABLE AccountToUser
CREATE INDEX fk_AuthToken_actionId
ON AuthToken (actionId);
+-- Fix missing user's id;
+DELETE FROM AuthToken
+WHERE userId NOT IN (SELECT id
+ FROM User);
+
ALTER TABLE AuthToken
ADD CONSTRAINT fk_AuthToken_userId
FOREIGN KEY (userId) REFERENCES User (id)
@@ -889,4 +751,6 @@ ALTER TABLE UserToUserGroup
ADD CONSTRAINT fk_UserToGroup_userGroupId
FOREIGN KEY (userGroupId) REFERENCES UserGroup (id)
ON UPDATE CASCADE
- ON DELETE CASCADE;
\ No newline at end of file
+ ON DELETE CASCADE;
+
+SET FOREIGN_KEY_CHECKS=1;
\ No newline at end of file