Improved compatibility with MySQL
This commit is contained in:
parent
6d7566ee2f
commit
c0bc4d4f19
31 changed files with 127 additions and 95 deletions
|
@ -12,6 +12,8 @@ activationBodyPath = mail/activation.txt
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
dsn = sqlite:db.sqlite
|
dsn = sqlite:db.sqlite
|
||||||
|
user =
|
||||||
|
password =
|
||||||
maxPostSize = 10485760 ;10mb
|
maxPostSize = 10485760 ;10mb
|
||||||
maxCustomThumbnailSize = 1048576 ;1mb
|
maxCustomThumbnailSize = 1048576 ;1mb
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,8 @@ abstract class AbstractDao implements ICrudDao
|
||||||
|
|
||||||
protected function findBy($columnName, $value)
|
protected function findBy($columnName, $value)
|
||||||
{
|
{
|
||||||
|
if (is_array($value) and empty($value))
|
||||||
|
return [];
|
||||||
$query = $this->fpdo->from($this->tableName)->where($columnName, $value);
|
$query = $this->fpdo->from($this->tableName)->where($columnName, $value);
|
||||||
$arrayEntities = iterator_to_array($query);
|
$arrayEntities = iterator_to_array($query);
|
||||||
return $this->arrayToEntities($arrayEntities);
|
return $this->arrayToEntities($arrayEntities);
|
||||||
|
|
|
@ -19,4 +19,16 @@ abstract class AbstractEntityConverter implements IEntityConverter
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract function toBasicEntity(array $array);
|
protected abstract function toBasicEntity(array $array);
|
||||||
|
|
||||||
|
protected function dbTimeToEntityTime($time)
|
||||||
|
{
|
||||||
|
if ($time === null)
|
||||||
|
return null;
|
||||||
|
return date('c', strtotime($time));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function entityTimeToDbTime($time)
|
||||||
|
{
|
||||||
|
return $time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class FavoriteEntityConverter extends AbstractEntityConverter implements IEntity
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'userId' => $entity->getUserId(),
|
'userId' => $entity->getUserId(),
|
||||||
'postId' => $entity->getPostId(),
|
'postId' => $entity->getPostId(),
|
||||||
'time' => $entity->getTime(),
|
'time' => $this->entityTimeToDbTime($entity->getTime()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class FavoriteEntityConverter extends AbstractEntityConverter implements IEntity
|
||||||
$entity = new \Szurubooru\Entities\Favorite($array['id']);
|
$entity = new \Szurubooru\Entities\Favorite($array['id']);
|
||||||
$entity->setUserId($array['userId']);
|
$entity->setUserId($array['userId']);
|
||||||
$entity->setPostId($array['postId']);
|
$entity->setPostId($array['postId']);
|
||||||
$entity->setTime($array['time']);
|
$entity->setTime($this->dbTimeToEntityTime($array['time']));
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,16 +8,16 @@ class GlobalParamEntityConverter extends AbstractEntityConverter implements IEnt
|
||||||
return
|
return
|
||||||
[
|
[
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'key' => $entity->getKey(),
|
'dataKey' => $entity->getKey(),
|
||||||
'value' => $entity->getValue(),
|
'dataValue' => $entity->getValue(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toBasicEntity(array $array)
|
public function toBasicEntity(array $array)
|
||||||
{
|
{
|
||||||
$entity = new \Szurubooru\Entities\GlobalParam($array['id']);
|
$entity = new \Szurubooru\Entities\GlobalParam($array['id']);
|
||||||
$entity->setKey($array['key']);
|
$entity->setKey($array['dataKey']);
|
||||||
$entity->setValue($array['value']);
|
$entity->setValue($array['dataValue']);
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'name' => $entity->getName(),
|
'name' => $entity->getName(),
|
||||||
'userId' => $entity->getUserId(),
|
'userId' => $entity->getUserId(),
|
||||||
'uploadTime' => $entity->getUploadTime(),
|
'uploadTime' => $this->entityTimeToDbTime($entity->getUploadTime()),
|
||||||
'lastEditTime' => $entity->getLastEditTime(),
|
'lastEditTime' => $this->entityTimeToDbTime($entity->getLastEditTime()),
|
||||||
'safety' => $entity->getSafety(),
|
'safety' => $entity->getSafety(),
|
||||||
'contentType' => $entity->getContentType(),
|
'contentType' => $entity->getContentType(),
|
||||||
'contentChecksum' => $entity->getContentChecksum(),
|
'contentChecksum' => $entity->getContentChecksum(),
|
||||||
|
@ -22,7 +22,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
|
||||||
'originalFileSize' => $entity->getOriginalFileSize(),
|
'originalFileSize' => $entity->getOriginalFileSize(),
|
||||||
'originalFileName' => $entity->getOriginalFileName(),
|
'originalFileName' => $entity->getOriginalFileName(),
|
||||||
'featureCount' => $entity->getFeatureCount(),
|
'featureCount' => $entity->getFeatureCount(),
|
||||||
'lastFeatureTime' => $entity->getLastFeatureTime(),
|
'lastFeatureTime' => $this->entityTimeToDbTime($entity->getLastFeatureTime()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
|
||||||
$entity = new \Szurubooru\Entities\Post(intval($array['id']));
|
$entity = new \Szurubooru\Entities\Post(intval($array['id']));
|
||||||
$entity->setName($array['name']);
|
$entity->setName($array['name']);
|
||||||
$entity->setUserId($array['userId']);
|
$entity->setUserId($array['userId']);
|
||||||
$entity->setUploadTime($array['uploadTime']);
|
$entity->setUploadTime($this->dbTimeToEntityTime($array['uploadTime']));
|
||||||
$entity->setLastEditTime($array['lastEditTime']);
|
$entity->setLastEditTime($this->dbTimeToEntityTime($array['lastEditTime']));
|
||||||
$entity->setSafety(intval($array['safety']));
|
$entity->setSafety(intval($array['safety']));
|
||||||
$entity->setContentType(intval($array['contentType']));
|
$entity->setContentType(intval($array['contentType']));
|
||||||
$entity->setContentChecksum($array['contentChecksum']);
|
$entity->setContentChecksum($array['contentChecksum']);
|
||||||
|
@ -43,7 +43,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
|
||||||
$entity->setOriginalFileSize($array['originalFileSize']);
|
$entity->setOriginalFileSize($array['originalFileSize']);
|
||||||
$entity->setOriginalFileName($array['originalFileName']);
|
$entity->setOriginalFileName($array['originalFileName']);
|
||||||
$entity->setFeatureCount(intval($array['featureCount']));
|
$entity->setFeatureCount(intval($array['featureCount']));
|
||||||
$entity->setLastFeatureTime($array['lastFeatureTime']);
|
$entity->setLastFeatureTime($this->dbTimeToEntityTime($array['lastFeatureTime']));
|
||||||
$entity->setMeta(\Szurubooru\Entities\Post::META_TAG_COUNT, intval($array['tagCount']));
|
$entity->setMeta(\Szurubooru\Entities\Post::META_TAG_COUNT, intval($array['tagCount']));
|
||||||
$entity->setMeta(\Szurubooru\Entities\Post::META_FAV_COUNT, intval($array['favCount']));
|
$entity->setMeta(\Szurubooru\Entities\Post::META_FAV_COUNT, intval($array['favCount']));
|
||||||
$entity->setMeta(\Szurubooru\Entities\Post::META_SCORE, intval($array['score']));
|
$entity->setMeta(\Szurubooru\Entities\Post::META_SCORE, intval($array['score']));
|
||||||
|
|
|
@ -10,7 +10,7 @@ class PostScoreEntityConverter extends AbstractEntityConverter implements IEntit
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'userId' => $entity->getUserId(),
|
'userId' => $entity->getUserId(),
|
||||||
'postId' => $entity->getPostId(),
|
'postId' => $entity->getPostId(),
|
||||||
'time' => $entity->getTime(),
|
'time' => $this->entityTimeToDbTime($entity->getTime()),
|
||||||
'score' => $entity->getScore(),
|
'score' => $entity->getScore(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ class PostScoreEntityConverter extends AbstractEntityConverter implements IEntit
|
||||||
$entity = new \Szurubooru\Entities\PostScore($array['id']);
|
$entity = new \Szurubooru\Entities\PostScore($array['id']);
|
||||||
$entity->setUserId($array['userId']);
|
$entity->setUserId($array['userId']);
|
||||||
$entity->setPostId($array['postId']);
|
$entity->setPostId($array['postId']);
|
||||||
$entity->setTime($array['time']);
|
$entity->setTime($this->dbTimeToEntityTime($array['time']));
|
||||||
$entity->setScore(intval($array['score']));
|
$entity->setScore(intval($array['score']));
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity
|
||||||
return
|
return
|
||||||
[
|
[
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'time' => $entity->getTime(),
|
'time' => $this->entityTimeToDbTime($entity->getTime()),
|
||||||
'type' => $entity->getType(),
|
'type' => $entity->getType(),
|
||||||
'primaryKey' => $entity->getPrimaryKey(),
|
'primaryKey' => $entity->getPrimaryKey(),
|
||||||
'userId' => $entity->getUserId(),
|
'userId' => $entity->getUserId(),
|
||||||
|
@ -21,7 +21,7 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity
|
||||||
public function toBasicEntity(array $array)
|
public function toBasicEntity(array $array)
|
||||||
{
|
{
|
||||||
$entity = new \Szurubooru\Entities\Snapshot(intval($array['id']));
|
$entity = new \Szurubooru\Entities\Snapshot(intval($array['id']));
|
||||||
$entity->setTime($array['time']);
|
$entity->setTime($this->dbTimeToEntityTime($array['time']));
|
||||||
$entity->setType(intval($array['type']));
|
$entity->setType(intval($array['type']));
|
||||||
$entity->setPrimaryKey($array['primaryKey']);
|
$entity->setPrimaryKey($array['primaryKey']);
|
||||||
$entity->setUserId($array['userId']);
|
$entity->setUserId($array['userId']);
|
||||||
|
|
|
@ -13,8 +13,8 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
|
||||||
'emailUnconfirmed' => $entity->getEmailUnconfirmed(),
|
'emailUnconfirmed' => $entity->getEmailUnconfirmed(),
|
||||||
'passwordHash' => $entity->getPasswordHash(),
|
'passwordHash' => $entity->getPasswordHash(),
|
||||||
'accessRank' => $entity->getAccessRank(),
|
'accessRank' => $entity->getAccessRank(),
|
||||||
'registrationTime' => $entity->getRegistrationTime(),
|
'registrationTime' => $this->entityTimeToDbTime($entity->getRegistrationTime()),
|
||||||
'lastLoginTime' => $entity->getLastLoginTime(),
|
'lastLoginTime' => $this->entityTimeToDbTime($entity->getLastLoginTime()),
|
||||||
'avatarStyle' => $entity->getAvatarStyle(),
|
'avatarStyle' => $entity->getAvatarStyle(),
|
||||||
'browsingSettings' => $entity->getBrowsingSettings(),
|
'browsingSettings' => $entity->getBrowsingSettings(),
|
||||||
'accountConfirmed' => $entity->isAccountConfirmed(),
|
'accountConfirmed' => $entity->isAccountConfirmed(),
|
||||||
|
@ -29,8 +29,8 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
|
||||||
$entity->setEmailUnconfirmed($array['emailUnconfirmed']);
|
$entity->setEmailUnconfirmed($array['emailUnconfirmed']);
|
||||||
$entity->setPasswordHash($array['passwordHash']);
|
$entity->setPasswordHash($array['passwordHash']);
|
||||||
$entity->setAccessRank(intval($array['accessRank']));
|
$entity->setAccessRank(intval($array['accessRank']));
|
||||||
$entity->setRegistrationTime($array['registrationTime']);
|
$entity->setRegistrationTime($this->dbTimeToEntityTime($array['registrationTime']));
|
||||||
$entity->setLastLoginTime($array['lastLoginTime']);
|
$entity->setLastLoginTime($this->dbTimeToEntityTime($array['lastLoginTime']));
|
||||||
$entity->setAvatarStyle(intval($array['avatarStyle']));
|
$entity->setAvatarStyle(intval($array['avatarStyle']));
|
||||||
$entity->setBrowsingSettings($array['browsingSettings']);
|
$entity->setBrowsingSettings($array['browsingSettings']);
|
||||||
$entity->setAccountConfirmed($array['accountConfirmed']);
|
$entity->setAccountConfirmed($array['accountConfirmed']);
|
||||||
|
|
|
@ -24,11 +24,11 @@ class GlobalParamDao extends AbstractDao implements ICrudDao
|
||||||
|
|
||||||
public function findByKey($key)
|
public function findByKey($key)
|
||||||
{
|
{
|
||||||
return $this->findOneBy('key', $key);
|
return $this->findOneBy('dataKey', $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteByKey($key)
|
public function deleteByKey($key)
|
||||||
{
|
{
|
||||||
return $this->deleteBy('key', $key);
|
return $this->deleteBy('dataKey', $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,8 @@ class DatabaseConnection
|
||||||
$cwd = getcwd();
|
$cwd = getcwd();
|
||||||
if ($this->config->getDataDirectory())
|
if ($this->config->getDataDirectory())
|
||||||
chdir($this->config->getDataDirectory());
|
chdir($this->config->getDataDirectory());
|
||||||
$this->pdo = new \PDO($this->config->database->dsn);
|
$this->pdo = new \PDO($this->config->database->dsn, $this->config->database->user,
|
||||||
|
$this->config->database->password);
|
||||||
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
chdir($cwd);
|
chdir($cwd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,8 @@ class UserEditFormData implements \Szurubooru\IValidatable
|
||||||
{
|
{
|
||||||
if (!is_string($this->browsingSettings))
|
if (!is_string($this->browsingSettings))
|
||||||
throw new \InvalidArgumentException('Browsing settings must be stringified JSON.');
|
throw new \InvalidArgumentException('Browsing settings must be stringified JSON.');
|
||||||
else if (strlen($this->browsingSettings) > 2000)
|
else if (strlen($this->browsingSettings) > 300)
|
||||||
throw new \InvalidArgumentException('Stringified browsing settings can have at most 2000 characters.');
|
throw new \InvalidArgumentException('Stringified browsing settings can have at most 300 characters.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,36 +5,38 @@ class Upgrade01 implements IUpgrade
|
||||||
{
|
{
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
|
$driver = $databaseConnection->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||||
|
|
||||||
$databaseConnection->getPDO()->exec('
|
$databaseConnection->getPDO()->exec('
|
||||||
CREATE TABLE "users"
|
CREATE TABLE users
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
name TEXT NOT NULL,
|
name VARCHAR(50) NOT NULL,
|
||||||
passwordHash TEXT NOT NULL,
|
passwordHash VARCHAR(64) NOT NULL,
|
||||||
email TEXT,
|
email VARCHAR(200),
|
||||||
emailUnconfirmed TEXT,
|
emailUnconfirmed VARCHAR(200),
|
||||||
accessRank INTEGER NOT NULL,
|
accessRank INTEGER NOT NULL,
|
||||||
browsingSettings TEXT,
|
browsingSettings VARCHAR(300),
|
||||||
banned INTEGER,
|
banned BOOLEAN DEFAULT FALSE,
|
||||||
registrationTime INTEGER DEFAULT NULL,
|
registrationTime DATETIME DEFAULT NULL,
|
||||||
lastLoginTime INTEGER DEFAULT NULL,
|
lastLoginTime DATETIME DEFAULT NULL,
|
||||||
avatarStyle INTEGER DEFAULT 1
|
avatarStyle INTEGER DEFAULT 1
|
||||||
);');
|
);');
|
||||||
|
|
||||||
$databaseConnection->getPDO()->exec('
|
$databaseConnection->getPDO()->exec('
|
||||||
CREATE TABLE "tokens"
|
CREATE TABLE tokens
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
name TEXT NOT NULL,
|
name VARCHAR(200) NOT NULL,
|
||||||
purpose INTEGER NOT NULL,
|
purpose INTEGER NOT NULL,
|
||||||
additionalData TEXT
|
additionalData VARCHAR(200)
|
||||||
);');
|
);');
|
||||||
|
|
||||||
$databaseConnection->getPDO()->exec('
|
$databaseConnection->getPDO()->exec('
|
||||||
CREATE TABLE "posts"
|
CREATE TABLE posts
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
name TEXT NOT NULL
|
name VARCHAR(200) NOT NULL
|
||||||
);');
|
);');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,6 @@ class Upgrade02 implements IUpgrade
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$databaseConnection->getPDO()->exec('
|
$databaseConnection->getPDO()->exec('
|
||||||
ALTER TABLE "users" ADD COLUMN accountConfirmed BOOLEAN NOT NULL DEFAULT FALSE');
|
ALTER TABLE users ADD COLUMN accountConfirmed BOOLEAN NOT NULL DEFAULT FALSE');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,37 +5,40 @@ class Upgrade03 implements IUpgrade
|
||||||
{
|
{
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$databaseConnection->getPDO()->exec('DROP TABLE "posts"');
|
$pdo = $databaseConnection->getPDO();
|
||||||
|
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||||
|
|
||||||
$databaseConnection->getPDO()->exec('
|
$pdo->exec('DROP TABLE IF EXISTS posts');
|
||||||
CREATE TABLE "posts"
|
|
||||||
|
$pdo->exec('
|
||||||
|
CREATE TABLE posts
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
name TEXT NOT NULL,
|
name VARCHAR(40) NOT NULL,
|
||||||
userId INTEGER,
|
userId INTEGER,
|
||||||
uploadTime TIMESTAMP NOT NULL,
|
uploadTime DATETIME NOT NULL,
|
||||||
lastEditTime TIMESTAMP,
|
lastEditTime DATETIME,
|
||||||
safety INTEGER NOT NULL,
|
safety INTEGER NOT NULL,
|
||||||
contentType INTEGER NOT NULL,
|
contentType INTEGER NOT NULL,
|
||||||
contentChecksum TEXT NOT NULL,
|
contentChecksum VARCHAR(64) NOT NULL,
|
||||||
source TEXT,
|
source VARCHAR(200),
|
||||||
imageWidth INTEGER,
|
imageWidth INTEGER,
|
||||||
imageHeight INTEGER,
|
imageHeight INTEGER,
|
||||||
originalFileSize INTEGER,
|
originalFileSize INTEGER,
|
||||||
originalFileName TEXT
|
originalFileName VARCHAR(200)
|
||||||
)');
|
)');
|
||||||
|
|
||||||
$databaseConnection->getPDO()->exec('
|
$pdo->exec('
|
||||||
CREATE TABLE "tags"
|
CREATE TABLE tags
|
||||||
(
|
(
|
||||||
name TEXT PRIMARY KEY NOT NULL
|
name VARCHAR(64) PRIMARY KEY NOT NULL
|
||||||
)');
|
)');
|
||||||
|
|
||||||
$databaseConnection->getPDO()->exec('
|
$pdo->exec('
|
||||||
CREATE TABLE "postTags"
|
CREATE TABLE postTags
|
||||||
(
|
(
|
||||||
postId INTEGER NOT NULL,
|
postId INTEGER NOT NULL,
|
||||||
tagName TEXT NOT NULL,
|
tagName VARCHAR(64) NOT NULL,
|
||||||
PRIMARY KEY (postId, tagName)
|
PRIMARY KEY (postId, tagName)
|
||||||
)');
|
)');
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Upgrade04 implements IUpgrade
|
||||||
|
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$databaseConnection->getPDO()->exec('ALTER TABLE "posts" ADD COLUMN contentMimeType TEXT DEFAULT NULL');
|
$databaseConnection->getPDO()->exec('ALTER TABLE posts ADD COLUMN contentMimeType VARCHAR(64) DEFAULT NULL');
|
||||||
|
|
||||||
$posts = $this->postDao->findAll();
|
$posts = $this->postDao->findAll();
|
||||||
foreach ($posts as $post)
|
foreach ($posts as $post)
|
||||||
|
|
|
@ -6,12 +6,13 @@ class Upgrade05 implements IUpgrade
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$pdo = $databaseConnection->getPDO();
|
$pdo = $databaseConnection->getPDO();
|
||||||
|
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||||
|
|
||||||
$pdo->exec('
|
$pdo->exec('
|
||||||
CREATE TABLE tags2
|
CREATE TABLE tags2
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
name TEXT UNIQUE NOT NULL,
|
name VARCHAR(64) UNIQUE NOT NULL,
|
||||||
usages INTEGER NOT NULL DEFAULT 0
|
usages INTEGER NOT NULL DEFAULT 0
|
||||||
)');
|
)');
|
||||||
$pdo->exec('INSERT INTO tags2(name, usages) SELECT name, (SELECT COUNT(1) FROM postTags WHERE tagName = tags.name) FROM tags');
|
$pdo->exec('INSERT INTO tags2(name, usages) SELECT name, (SELECT COUNT(1) FROM postTags WHERE tagName = tags.name) FROM tags');
|
||||||
|
|
|
@ -7,8 +7,6 @@ class Upgrade06 implements IUpgrade
|
||||||
{
|
{
|
||||||
$pdo = $databaseConnection->getPDO();
|
$pdo = $databaseConnection->getPDO();
|
||||||
|
|
||||||
$pdo->exec('ALTER TABLE posts ADD COLUMN tagCount INTEGER NOT NULL DEFAULT 0');
|
|
||||||
|
|
||||||
$pdo->exec('
|
$pdo->exec('
|
||||||
CREATE TRIGGER postTagsDelete BEFORE DELETE ON postTags
|
CREATE TRIGGER postTagsDelete BEFORE DELETE ON postTags
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
|
@ -34,5 +32,7 @@ class Upgrade06 implements IUpgrade
|
||||||
UPDATE tags SET usages = usages + 1 WHERE tags.id = NEW.tagId;
|
UPDATE tags SET usages = usages + 1 WHERE tags.id = NEW.tagId;
|
||||||
UPDATE tags SET usages = usages - 1 WHERE tags.id = OLD.tagId;
|
UPDATE tags SET usages = usages - 1 WHERE tags.id = OLD.tagId;
|
||||||
END');
|
END');
|
||||||
|
|
||||||
|
$pdo->exec('ALTER TABLE posts ADD COLUMN tagCount INTEGER NOT NULL DEFAULT 0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,16 @@ class Upgrade07 implements IUpgrade
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$pdo = $databaseConnection->getPDO();
|
$pdo = $databaseConnection->getPDO();
|
||||||
|
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||||
$pdo->exec('ALTER TABLE posts ADD COLUMN featureCount INTEGER NOT NULL DEFAULT 0');
|
|
||||||
$pdo->exec('ALTER TABLE posts ADD COLUMN lastFeatureTime TIMESTAMP');
|
|
||||||
|
|
||||||
$pdo->exec('CREATE TABLE globals
|
$pdo->exec('CREATE TABLE globals
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
key TEXT UNIQUE NOT NULL,
|
dataKey VARCHAR(32) UNIQUE NOT NULL,
|
||||||
value TEXT
|
dataValue VARCHAR(64)
|
||||||
)');
|
)');
|
||||||
|
|
||||||
|
$pdo->exec('ALTER TABLE posts ADD COLUMN featureCount INTEGER NOT NULL DEFAULT 0');
|
||||||
|
$pdo->exec('ALTER TABLE posts ADD COLUMN lastFeatureTime DATETIME');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,11 @@ class Upgrade08 implements IUpgrade
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$pdo = $databaseConnection->getPDO();
|
$pdo = $databaseConnection->getPDO();
|
||||||
|
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||||
|
|
||||||
$pdo->exec('CREATE TABLE postRelations
|
$pdo->exec('CREATE TABLE postRelations
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
post1id INTEGER NOT NULL,
|
post1id INTEGER NOT NULL,
|
||||||
post2id INTEGER NOT NULL,
|
post2id INTEGER NOT NULL,
|
||||||
UNIQUE (post1id, post2id)
|
UNIQUE (post1id, post2id)
|
||||||
|
|
|
@ -17,13 +17,14 @@ class Upgrade09 implements IUpgrade
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$pdo = $databaseConnection->getPDO();
|
$pdo = $databaseConnection->getPDO();
|
||||||
|
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||||
|
|
||||||
$pdo->exec('DROP TABLE IF EXISTS snapshots');
|
$pdo->exec('DROP TABLE IF EXISTS snapshots');
|
||||||
|
|
||||||
$pdo->exec('CREATE TABLE snapshots
|
$pdo->exec('CREATE TABLE snapshots
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
time TIMESTAMP NOT NULL,
|
time DATETIME NOT NULL,
|
||||||
type INTEGER NOT NULL,
|
type INTEGER NOT NULL,
|
||||||
primaryKey TEXT NOT NULL,
|
primaryKey TEXT NOT NULL,
|
||||||
operation INTEGER NOT NULL,
|
operation INTEGER NOT NULL,
|
||||||
|
|
|
@ -6,16 +6,14 @@ class Upgrade10 implements IUpgrade
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$pdo = $databaseConnection->getPDO();
|
$pdo = $databaseConnection->getPDO();
|
||||||
|
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||||
$pdo->exec('ALTER TABLE posts ADD COLUMN favCount INTEGER NOT NULL DEFAULT 0');
|
|
||||||
$pdo->exec('ALTER TABLE posts ADD COLUMN lastFavTime TIMESTAMP');
|
|
||||||
|
|
||||||
$pdo->exec('CREATE TABLE favorites
|
$pdo->exec('CREATE TABLE favorites
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
userId INTEGER NOT NULL,
|
userId INTEGER NOT NULL,
|
||||||
postId INTEGER NOT NULL,
|
postId INTEGER NOT NULL,
|
||||||
time TIMESTAMP NOT NULL,
|
time DATETIME NOT NULL,
|
||||||
UNIQUE (userId, postId)
|
UNIQUE (userId, postId)
|
||||||
)');
|
)');
|
||||||
|
|
||||||
|
@ -55,5 +53,8 @@ class Upgrade10 implements IUpgrade
|
||||||
WHERE favorites.postId = posts.id)
|
WHERE favorites.postId = posts.id)
|
||||||
WHERE posts.id IN (OLD.postId, NEW.postId);
|
WHERE posts.id IN (OLD.postId, NEW.postId);
|
||||||
END');
|
END');
|
||||||
|
|
||||||
|
$pdo->exec('ALTER TABLE posts ADD COLUMN favCount INTEGER NOT NULL DEFAULT 0');
|
||||||
|
$pdo->exec('ALTER TABLE posts ADD COLUMN lastFavTime DATETIME');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,14 @@ class Upgrade11 implements IUpgrade
|
||||||
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
{
|
{
|
||||||
$pdo = $databaseConnection->getPDO();
|
$pdo = $databaseConnection->getPDO();
|
||||||
|
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||||
$pdo->exec('ALTER TABLE posts ADD COLUMN score INTEGER NOT NULL DEFAULT 0');
|
|
||||||
|
|
||||||
$pdo->exec('CREATE TABLE postScores
|
$pdo->exec('CREATE TABLE postScores
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
|
||||||
userId INTEGER NOT NULL,
|
userId INTEGER NOT NULL,
|
||||||
postId INTEGER NOT NULL,
|
postId INTEGER NOT NULL,
|
||||||
time TIMESTAMP NOT NULL,
|
time DATETIME NOT NULL,
|
||||||
score INTEGER NOT NULL,
|
score INTEGER NOT NULL,
|
||||||
UNIQUE (userId, postId)
|
UNIQUE (userId, postId)
|
||||||
)');
|
)');
|
||||||
|
@ -54,5 +53,7 @@ class Upgrade11 implements IUpgrade
|
||||||
WHERE postScores.postId = posts.id)
|
WHERE postScores.postId = posts.id)
|
||||||
WHERE posts.id = NEW.postId;
|
WHERE posts.id = NEW.postId;
|
||||||
END');
|
END');
|
||||||
|
|
||||||
|
$pdo->exec('ALTER TABLE posts ADD COLUMN score INTEGER NOT NULL DEFAULT 0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,8 @@ class Validator
|
||||||
throw new \DomainException('Tags cannot be empty.');
|
throw new \DomainException('Tags cannot be empty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->validateMaxLength($tag, 64, 'Tag');
|
||||||
|
|
||||||
foreach ($illegalCharacters as $char)
|
foreach ($illegalCharacters as $char)
|
||||||
{
|
{
|
||||||
if (strpos($tag, $char) !== false)
|
if (strpos($tag, $char) !== false)
|
||||||
|
|
|
@ -10,6 +10,8 @@ abstract class AbstractDatabaseTestCase extends \Szurubooru\Tests\AbstractTestCa
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$config = $this->mockConfig($this->createTestDirectory());
|
$config = $this->mockConfig($this->createTestDirectory());
|
||||||
$config->set('database/dsn', 'sqlite::memory:');
|
$config->set('database/dsn', 'sqlite::memory:');
|
||||||
|
$config->set('database/user', '');
|
||||||
|
$config->set('database/password', '');
|
||||||
|
|
||||||
$this->databaseConnection = new \Szurubooru\DatabaseConnection($config);
|
$this->databaseConnection = new \Szurubooru\DatabaseConnection($config);
|
||||||
\Szurubooru\Injector::set(\Szurubooru\DatabaseConnection::class, $this->databaseConnection);
|
\Szurubooru\Injector::set(\Szurubooru\DatabaseConnection::class, $this->databaseConnection);
|
||||||
|
|
|
@ -26,7 +26,7 @@ class FavoritesDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
$favorite = new \Szurubooru\Entities\Favorite();
|
$favorite = new \Szurubooru\Entities\Favorite();
|
||||||
$favorite->setUser($user);
|
$favorite->setUser($user);
|
||||||
$favorite->setPost($post);
|
$favorite->setPost($post);
|
||||||
$favorite->setTime('whatever');
|
$favorite->setTime(date('c'));
|
||||||
$favoritesDao = $this->getFavoritesDao();
|
$favoritesDao = $this->getFavoritesDao();
|
||||||
$favoritesDao->save($favorite);
|
$favoritesDao->save($favorite);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class FavoritesDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
$savedFavorite = $favoritesDao->findById($favorite->getId());
|
$savedFavorite = $favoritesDao->findById($favorite->getId());
|
||||||
$this->assertEquals(1, $savedFavorite->getUserId());
|
$this->assertEquals(1, $savedFavorite->getUserId());
|
||||||
$this->assertEquals(2, $savedFavorite->getPostId());
|
$this->assertEquals(2, $savedFavorite->getPostId());
|
||||||
$this->assertEquals('whatever', $savedFavorite->getTime());
|
$this->assertEquals($favorite->getTime(), $savedFavorite->getTime());
|
||||||
$this->assertEntitiesEqual($user, $savedFavorite->getUser());
|
$this->assertEntitiesEqual($user, $savedFavorite->getUser());
|
||||||
$this->assertEntitiesEqual($post, $savedFavorite->getPost());
|
$this->assertEntitiesEqual($post, $savedFavorite->getPost());
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
$post = new \Szurubooru\Entities\Post();
|
$post = new \Szurubooru\Entities\Post();
|
||||||
$post->setName('test');
|
$post->setName('test');
|
||||||
$post->setUploadTime('whatever');
|
$post->setUploadTime(date('c'));
|
||||||
$post->setSafety(\Szurubooru\Entities\Post::POST_SAFETY_SAFE);
|
$post->setSafety(\Szurubooru\Entities\Post::POST_SAFETY_SAFE);
|
||||||
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_YOUTUBE);
|
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_YOUTUBE);
|
||||||
$post->setContentChecksum('whatever');
|
$post->setContentChecksum('whatever');
|
||||||
|
|
|
@ -26,7 +26,7 @@ class PostScoreDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
$postScore = new \Szurubooru\Entities\PostScore();
|
$postScore = new \Szurubooru\Entities\PostScore();
|
||||||
$postScore->setUser($user);
|
$postScore->setUser($user);
|
||||||
$postScore->setPost($post);
|
$postScore->setPost($post);
|
||||||
$postScore->setTime('whatever');
|
$postScore->setTime(date('c'));
|
||||||
$postScore->setScore(1);
|
$postScore->setScore(1);
|
||||||
$postScoreDao = $this->getPostScoreDao();
|
$postScoreDao = $this->getPostScoreDao();
|
||||||
$postScoreDao->save($postScore);
|
$postScoreDao->save($postScore);
|
||||||
|
@ -37,7 +37,7 @@ class PostScoreDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
$savedPostScore = $postScoreDao->findById($postScore->getId());
|
$savedPostScore = $postScoreDao->findById($postScore->getId());
|
||||||
$this->assertEquals(1, $savedPostScore->getUserId());
|
$this->assertEquals(1, $savedPostScore->getUserId());
|
||||||
$this->assertEquals(2, $savedPostScore->getPostId());
|
$this->assertEquals(2, $savedPostScore->getPostId());
|
||||||
$this->assertEquals('whatever', $savedPostScore->getTime());
|
$this->assertEquals($postScore->getTime(), $savedPostScore->getTime());
|
||||||
$this->assertEntitiesEqual($user, $savedPostScore->getUser());
|
$this->assertEntitiesEqual($user, $savedPostScore->getUser());
|
||||||
$this->assertEntitiesEqual($post, $savedPostScore->getPost());
|
$this->assertEntitiesEqual($post, $savedPostScore->getPost());
|
||||||
}
|
}
|
||||||
|
@ -52,19 +52,19 @@ class PostScoreDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
$postScore1 = new \Szurubooru\Entities\PostScore();
|
$postScore1 = new \Szurubooru\Entities\PostScore();
|
||||||
$postScore1->setUser($user1);
|
$postScore1->setUser($user1);
|
||||||
$postScore1->setPost($post1);
|
$postScore1->setPost($post1);
|
||||||
$postScore1->setTime('time1');
|
$postScore1->setTime(date('c', mktime(1)));
|
||||||
$postScore1->setScore(1);
|
$postScore1->setScore(1);
|
||||||
|
|
||||||
$postScore2 = new \Szurubooru\Entities\PostScore();
|
$postScore2 = new \Szurubooru\Entities\PostScore();
|
||||||
$postScore2->setUser($user2);
|
$postScore2->setUser($user2);
|
||||||
$postScore2->setPost($post2);
|
$postScore2->setPost($post2);
|
||||||
$postScore2->setTime('time2');
|
$postScore2->setTime(date('c', mktime(2)));
|
||||||
$postScore2->setScore(0);
|
$postScore2->setScore(0);
|
||||||
|
|
||||||
$postScore3 = new \Szurubooru\Entities\PostScore();
|
$postScore3 = new \Szurubooru\Entities\PostScore();
|
||||||
$postScore3->setUser($user1);
|
$postScore3->setUser($user1);
|
||||||
$postScore3->setPost($post2);
|
$postScore3->setPost($post2);
|
||||||
$postScore3->setTime('time3');
|
$postScore3->setTime(date('c', mktime(3)));
|
||||||
$postScore3->setScore(-1);
|
$postScore3->setScore(-1);
|
||||||
|
|
||||||
$postScoreDao = $this->getPostScoreDao();
|
$postScoreDao = $this->getPostScoreDao();
|
||||||
|
|
|
@ -40,7 +40,7 @@ class SnapshotDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
$snapshot->setType(\Szurubooru\Entities\Snapshot::TYPE_POST);
|
$snapshot->setType(\Szurubooru\Entities\Snapshot::TYPE_POST);
|
||||||
$snapshot->setData(['wake up', 'neo', ['follow' => 'white rabbit']]);
|
$snapshot->setData(['wake up', 'neo', ['follow' => 'white rabbit']]);
|
||||||
$snapshot->setPrimaryKey(1);
|
$snapshot->setPrimaryKey(1);
|
||||||
$snapshot->setTime('whateveer');
|
$snapshot->setTime(date('c', mktime(1, 2, 3)));
|
||||||
$snapshot->setUserId(null);
|
$snapshot->setUserId(null);
|
||||||
$snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_CHANGE);
|
$snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_CHANGE);
|
||||||
return $snapshot;
|
return $snapshot;
|
||||||
|
|
|
@ -151,8 +151,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
$user = new \Szurubooru\Entities\User();
|
$user = new \Szurubooru\Entities\User();
|
||||||
$user->setName($userName);
|
$user->setName($userName);
|
||||||
$user->setPasswordHash('whatever');
|
$user->setPasswordHash('whatever');
|
||||||
$user->setLastLoginTime('whatever');
|
$user->setLastLoginTime(date('c', mktime(1, 2, 3)));
|
||||||
$user->setRegistrationTime('whatever');
|
$user->setRegistrationTime(date('c', mktime(3, 2, 1)));
|
||||||
$user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER);
|
$user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER);
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,8 +114,8 @@ final class UserDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
$user = new \Szurubooru\Entities\User();
|
$user = new \Szurubooru\Entities\User();
|
||||||
$user->setName('test');
|
$user->setName('test');
|
||||||
$user->setPasswordHash('whatever');
|
$user->setPasswordHash('whatever');
|
||||||
$user->setLastLoginTime('whatever');
|
$user->setLastLoginTime(date('c', mktime(1, 2, 3)));
|
||||||
$user->setRegistrationTime('whatever');
|
$user->setRegistrationTime(date('c', mktime(3, 2, 1)));
|
||||||
$user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER);
|
$user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER);
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue