- change engine of ?_account*-tables to InnoDB
 - link userId of ?_account*, ?_screenshot & ?_videos -tables using foreign keys
 - also display screenshots/videos, that do not have an owner
This commit is contained in:
Sarjuuk
2015-06-09 00:03:48 +02:00
parent 7a0c6f22dc
commit a4c76de124
6 changed files with 113 additions and 21 deletions

View File

@@ -629,7 +629,7 @@ class AjaxHandler
{ {
if (!isset($this->post['id'])) if (!isset($this->post['id']))
{ {
$res = DB::Aowow()->selectRow('SELECT max(id) as max, count(id) as num FROM ?_account_weightscales WHERE account = ?d', User::$id); $res = DB::Aowow()->selectRow('SELECT max(id) as max, count(id) as num FROM ?_account_weightscales WHERE userId = ?d', User::$id);
if ($res['num'] < 5) // more or less hard-defined in LANG.message_weightscalesaveerror if ($res['num'] < 5) // more or less hard-defined in LANG.message_weightscalesaveerror
$this->post['id'] = ++$res['max']; $this->post['id'] = ++$res['max'];
else else
@@ -642,7 +642,7 @@ class AjaxHandler
return 0; return 0;
} }
else if ($this->post('delete') && $this->post('id')) else if ($this->post('delete') && $this->post('id'))
DB::Aowow()->query('DELETE FROM ?_account_weightscales WHERE id = ?d AND account = ?d', intVal($this->post('id')), User::$id); DB::Aowow()->query('DELETE FROM ?_account_weightscales WHERE id = ?d AND userId = ?d', intVal($this->post('id')), User::$id);
else else
return 0; return 0;
} }
@@ -782,7 +782,7 @@ class AjaxHandler
$id = $matches[1]; $id = $matches[1];
$dest = imageCreateTruecolor($s[$size], $s[$size]); $dest = imageCreateTruecolor($s[$size], $s[$size]);
if (file_exists('/uploads/avatars/'.$id.'.jpg')) if (file_exists('uploads/avatars/'.$id.'.jpg'))
{ {
$offsetX = $offsetY = 0; $offsetX = $offsetY = 0;
@@ -1167,7 +1167,7 @@ class AjaxHandler
foreach ($ids as $id) foreach ($ids as $id)
{ {
// must not be already approved // must not be already approved
if ($_ = DB::Aowow()->selectCell('SELECT uploader FROM ?_screenshots WHERE (status & ?d) = 0 AND id = ?d', CC_FLAG_APPROVED, $id)) if ($_ = DB::Aowow()->selectCell('SELECT userIdOwner FROM ?_screenshots WHERE (status & ?d) = 0 AND id = ?d', CC_FLAG_APPROVED, $id))
{ {
// should also error-log // should also error-log
if (!file_exists(sprintf($path, 'pending', $id))) if (!file_exists(sprintf($path, 'pending', $id)))
@@ -1208,7 +1208,7 @@ class AjaxHandler
rename(sprintf($path, 'pending', $id), sprintf($path, 'normal', $id)); rename(sprintf($path, 'pending', $id), sprintf($path, 'normal', $id));
// set as approved in DB and gain rep (once!) // set as approved in DB and gain rep (once!)
DB::Aowow()->query('UPDATE ?_screenshots SET status = ?d, approvedBy = ?d WHERE id = ?d', CC_FLAG_APPROVED, User::$id, $id); DB::Aowow()->query('UPDATE ?_screenshots SET status = ?d, userIdApprove = ?d WHERE id = ?d', CC_FLAG_APPROVED, User::$id, $id);
Util::gainSiteReputation($_, SITEREP_ACTION_UPLOAD, ['id' => $id, 'what' => 1]); Util::gainSiteReputation($_, SITEREP_ACTION_UPLOAD, ['id' => $id, 'what' => 1]);
} }
} }
@@ -1279,7 +1279,7 @@ class AjaxHandler
} }
// flag as deleted if not aready // flag as deleted if not aready
DB::Aowow()->query('UPDATE ?_screenshots SET status = ?d, deletedBy = ?d WHERE id IN (?a)', CC_FLAG_DELETED, User::$id, $ids); DB::Aowow()->query('UPDATE ?_screenshots SET status = ?d, userIdDelete = ?d WHERE id IN (?a)', CC_FLAG_DELETED, User::$id, $ids);
return ''; return '';
} }

View File

@@ -237,14 +237,14 @@ class CommunityContent
public static function getScreenshotsForManager($type, $typeId, $userId = 0) public static function getScreenshotsForManager($type, $typeId, $userId = 0)
{ {
$screenshots = DB::Aowow()->select(' $screenshots = DB::Aowow()->select('
SELECT s.id, a.displayName AS user, s.date, s.width, s.height, s.type, s.typeId, s.caption, s.status, s.status AS "flags" SELECT s.id, a.displayName AS user, s.date, s.width, s.height, s.type, s.typeId, s.caption, s.status, s.status AS "flags"
FROM ?_screenshots s, ?_account a FROM ?_screenshots s,
LEFT JOIN ?_account a ON s.userIdOwner = a.id
WHERE WHERE
s.uploader = a.id AND { s.type = ?d}
{ s.type = ?d} { AND s.typeId = ?d}
{ AND s.typeId = ?d} { s.userIdOwner = ?d}
{ s.uploader = ?d} LIMIT 100',
LIMIT 100',
$userId ? DBSIMPLE_SKIP : $type, $userId ? DBSIMPLE_SKIP : $type,
$userId ? DBSIMPLE_SKIP : $typeId, $userId ? DBSIMPLE_SKIP : $typeId,
$userId ? $userId : DBSIMPLE_SKIP $userId ? $userId : DBSIMPLE_SKIP
@@ -296,6 +296,9 @@ class CommunityContent
// something todo with massSelect .. am i doing this right? // something todo with massSelect .. am i doing this right?
if ($num[$s['type']][$s['typeId']] == 1) if ($num[$s['type']][$s['typeId']] == 1)
$s['unique'] = 1; $s['unique'] = 1;
if (!$s['user'])
unset($s['user']);
} }
return $screenshots; return $screenshots;
@@ -418,8 +421,9 @@ class CommunityContent
{ {
$videos = DB::Aowow()->selectPage($nFound, " $videos = DB::Aowow()->selectPage($nFound, "
SELECT v.id, a.displayName AS user, v.date, v.videoId, v.caption, IF(v.status & ?d, 1, 0) AS 'sticky', v.type, v.typeId SELECT v.id, a.displayName AS user, v.date, v.videoId, v.caption, IF(v.status & ?d, 1, 0) AS 'sticky', v.type, v.typeId
FROM ?_videos v, ?_account a FROM ?_videos v
WHERE {v.uploader = ?d }{v.type = ? }{AND v.typeId = ? }AND v.status & ?d AND (v.status & ?d) = 0 AND v.uploader = a.id", LEFT JOIN ?_account a ON v.userIdOwner = a.id
WHERE {v.userIdOwner = ?d }{v.type = ? }{AND v.typeId = ? }AND v.status & ?d AND (v.status & ?d) = 0",
CC_FLAG_STICKY, CC_FLAG_STICKY,
$typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP,
$typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP,
@@ -449,8 +453,12 @@ class CommunityContent
$v['date'] = date(Util::$dateFormatInternal, $v['date']); $v['date'] = date(Util::$dateFormatInternal, $v['date']);
$v['videoType'] = 1; // always youtube $v['videoType'] = 1; // always youtube
if (!$v['sticky']) if (!$v['sticky'])
unset($v['sticky']); unset($v['sticky']);
if (!$v['user'])
unset($v['user']);
} }
return $videos; return $videos;
@@ -460,8 +468,9 @@ class CommunityContent
{ {
$screenshots = DB::Aowow()->selectPage($nFound, " $screenshots = DB::Aowow()->selectPage($nFound, "
SELECT s.id, a.displayName AS user, s.date, s.width, s.height, s.caption, IF(s.status & ?d, 1, 0) AS 'sticky', s.type, s.typeId SELECT s.id, a.displayName AS user, s.date, s.width, s.height, s.caption, IF(s.status & ?d, 1, 0) AS 'sticky', s.type, s.typeId
FROM ?_screenshots s, ?_account a FROM ?_screenshots s
WHERE {s.uploader = ?d }{s.type = ? }{AND s.typeId = ? }AND s.status & ?d AND (s.status & ?d) = 0 AND s.uploader = a.id", LEFT JOIN ?_account a ON s.userIdOwner = a.id
WHERE {s.userIdOwner = ?d }{s.type = ? }{AND s.typeId = ? }AND s.status & ?d AND (s.status & ?d) = 0",
CC_FLAG_STICKY, CC_FLAG_STICKY,
$typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP, $typeOrUser < 0 ? -$typeOrUser : DBSIMPLE_SKIP,
$typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP, $typeOrUser > 0 ? $typeOrUser : DBSIMPLE_SKIP,
@@ -490,8 +499,12 @@ class CommunityContent
} }
$s['date'] = date(Util::$dateFormatInternal, $s['date']); $s['date'] = date(Util::$dateFormatInternal, $s['date']);
if (!$s['sticky']) if (!$s['sticky'])
unset($s['sticky']); unset($s['sticky']);
if (!$s['user'])
unset($s['user']);
} }
return $screenshots; return $screenshots;

View File

@@ -525,7 +525,7 @@ class User
{ {
$data = []; $data = [];
$res = DB::Aowow()->select('SELECT * FROM ?_account_weightscales WHERE account = ?d', self::$id); $res = DB::Aowow()->select('SELECT * FROM ?_account_weightscales WHERE userId = ?d', self::$id);
foreach ($res as $i) foreach ($res as $i)
{ {
$set = array ( $set = array (

View File

@@ -104,7 +104,7 @@ class ScreenshotPage extends GenericPage
// write to db // write to db
$newId = DB::Aowow()->query( $newId = DB::Aowow()->query(
'INSERT INTO ?_screenshots (type, typeId, uploader, date, width, height, caption) VALUES (?d, ?d, ?d, UNIX_TIMESTAMP(), ?d, ?d, ?)', 'INSERT INTO ?_screenshots (type, typeId, userIdOwner, date, width, height, caption) VALUES (?d, ?d, ?d, UNIX_TIMESTAMP(), ?d, ?d, ?)',
$_SESSION['ssUpload']['type'], $_SESSION['ssUpload']['typeId'], $_SESSION['ssUpload']['type'], $_SESSION['ssUpload']['typeId'],
User::$id, User::$id,
$w, $h, $w, $h,

View File

@@ -61,7 +61,7 @@ class UserPage extends GenericPage
if ($co['sum']) if ($co['sum'])
$contrib[] = Lang::user('comments').Lang::main('colon').$co['sum'].' [small]([tooltip=tooltip_totalratings]'.$co['nRates'].'[/tooltip])[/small]'; $contrib[] = Lang::user('comments').Lang::main('colon').$co['sum'].' [small]([tooltip=tooltip_totalratings]'.$co['nRates'].'[/tooltip])[/small]';
$ss = DB::Aowow()->selectRow('SELECT COUNT(id) AS sum, SUM(IF(status & ?d, 1, 0)) as nSticky FROM ?_screenshots WHERE uploader = ?d AND status & ?d AND (status & ?d) = 0', $ss = DB::Aowow()->selectRow('SELECT COUNT(id) AS sum, SUM(IF(status & ?d, 1, 0)) as nSticky FROM ?_screenshots WHERE userIdOwner = ?d AND status & ?d AND (status & ?d) = 0',
CC_FLAG_STICKY, CC_FLAG_STICKY,
$this->user['id'], $this->user['id'],
CC_FLAG_APPROVED, CC_FLAG_APPROVED,
@@ -70,7 +70,7 @@ class UserPage extends GenericPage
if ($ss['sum']) if ($ss['sum'])
$contrib[] = Lang::user('screenshots').Lang::main('colon').$ss['sum'].' [small]([tooltip=tooltip_normal]'.($ss['sum'] - $ss['nSticky']).'[/tooltip] + [tooltip=tooltip_sticky]'.$ss['nSticky'].'[/tooltip])[/small]'; $contrib[] = Lang::user('screenshots').Lang::main('colon').$ss['sum'].' [small]([tooltip=tooltip_normal]'.($ss['sum'] - $ss['nSticky']).'[/tooltip] + [tooltip=tooltip_sticky]'.$ss['nSticky'].'[/tooltip])[/small]';
$vi = DB::Aowow()->selectRow('SELECT COUNT(id) AS sum, SUM(IF(status & ?d, 1, 0)) as nSticky FROM ?_videos WHERE uploader = ?d AND status & ?d AND (status & ?d) = 0', $vi = DB::Aowow()->selectRow('SELECT COUNT(id) AS sum, SUM(IF(status & ?d, 1, 0)) as nSticky FROM ?_videos WHERE userIdOwner = ?d AND status & ?d AND (status & ?d) = 0',
CC_FLAG_STICKY, CC_FLAG_STICKY,
$this->user['id'], $this->user['id'],
CC_FLAG_APPROVED, CC_FLAG_APPROVED,

View File

@@ -0,0 +1,79 @@
-- ***************************
-- * change engine to InnoDB *
-- * unify userId-fields *
-- ***************************
ALTER TABLE `aowow_account`
ENGINE=InnoDB,
ROW_FORMAT=COMPACT;
ALTER TABLE `aowow_account_banned`
ALTER `userId` DROP DEFAULT,
ALTER `staffId` DROP DEFAULT;
ALTER TABLE `aowow_account_banned`
ENGINE=InnoDB,
ROW_FORMAT=COMPACT,
CHANGE COLUMN `userId` `userId` INT(10) UNSIGNED NOT NULL COMMENT 'affected accountId' AFTER `id`,
CHANGE COLUMN `staffId` `staffId` INT(10) UNSIGNED NOT NULL COMMENT 'executive accountId' AFTER `userId`;
ALTER TABLE `aowow_account_cookies`
ENGINE=InnoDB,
ROW_FORMAT=COMPACT;
ALTER TABLE `aowow_account_reputation`
ENGINE=InnoDB,
ROW_FORMAT=COMPACT;
ALTER TABLE `aowow_account_weightscales`
ALTER `account` DROP DEFAULT;
ALTER TABLE `aowow_account_weightscales`
ENGINE=InnoDB,
ROW_FORMAT=COMPACT,
CHANGE COLUMN `account` `userId` INT(10) UNSIGNED NOT NULL AFTER `id`;
ALTER TABLE `aowow_screenshots`
ALTER `uploader` DROP DEFAULT;
ALTER TABLE `aowow_screenshots`
ENGINE=InnoDB,
ROW_FORMAT=COMPACT,
CHANGE COLUMN `uploader` `userIdOwner` INT(10) UNSIGNED NULL AFTER `typeId`,
CHANGE COLUMN `approvedBy` `userIdApprove` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `status`,
CHANGE COLUMN `deletedBy` `userIdDelete` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `userIdApprove`;
ALTER TABLE `aowow_videos`
ALTER `uploader` DROP DEFAULT;
ALTER TABLE `aowow_videos`
ENGINE=InnoDB,
ROW_FORMAT=COMPACT,
CHANGE COLUMN `uploader` `userIdOwner` INT(10) UNSIGNED NULL AFTER `typeId`,
CHANGE COLUMN `approvedBy` `userIdApprove` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `status`,
ADD COLUMN `userIdeDelete` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `userIdApprove`;
-- **********************
-- * apply foreign keys *
-- **********************
ALTER TABLE aowow_account_cookies ADD CONSTRAINT FK_acc_cookies FOREIGN KEY (userId) REFERENCES aowow_account(id)
ON UPDATE CASCADE
ON DELETE CASCADE
;
ALTER TABLE aowow_account_banned ADD CONSTRAINT FK_acc_banned FOREIGN KEY (userId) REFERENCES aowow_account(id)
ON UPDATE CASCADE
ON DELETE CASCADE
;
ALTER TABLE aowow_account_reputation ADD CONSTRAINT FK_acc_rep FOREIGN KEY (userId) REFERENCES aowow_account(id)
ON UPDATE CASCADE
ON DELETE CASCADE
;
ALTER TABLE aowow_account_weightscales ADD CONSTRAINT FK_acc_weights FOREIGN KEY (userId) REFERENCES aowow_account(id)
ON UPDATE CASCADE
ON DELETE CASCADE
;
ALTER TABLE aowow_screenshots ADD CONSTRAINT FK_acc_ss FOREIGN KEY (userIdOwner) REFERENCES aowow_account(id)
ON UPDATE CASCADE
ON DELETE SET NULL
;
ALTER TABLE aowow_videos ADD CONSTRAINT FK_acc_vi FOREIGN KEY (userIdOwner) REFERENCES aowow_account(id)
ON UPDATE CASCADE
ON DELETE SET NULL
;