Screenshots

* aproving a screenshot now flags the corresponding db entry as having a screenshot
 * deleting & moving screenshots works equivalent
 * instancing a new TypeClass without parameters no longer grabs everything from the corresponding tables ( pass a "[true]" to retain this behaviour)
 * retroactively flag db entries for having screenshots
 * fixed a typo
This commit is contained in:
Sarjuuk
2017-02-23 12:06:20 +01:00
parent ab8d7caced
commit 99760d7c72
28 changed files with 301 additions and 166 deletions

View File

@@ -128,7 +128,7 @@ class AjaxAdmin extends AjaxHandler
foreach ($this->_get['id'] as $id)
{
// must not be already approved
if ($_ = DB::Aowow()->selectRow('SELECT userIdOwner, date FROM ?_screenshots WHERE (status & ?d) = 0 AND id = ?d', CC_FLAG_APPROVED, $id))
if ($_ = DB::Aowow()->selectRow('SELECT userIdOwner, date, type, typeId FROM ?_screenshots WHERE (status & ?d) = 0 AND id = ?d', CC_FLAG_APPROVED, $id))
{
// should also error-log
if (!file_exists(sprintf($path, 'pending', $id)))
@@ -171,6 +171,9 @@ class AjaxAdmin extends AjaxHandler
// set as approved in DB and gain rep (once!)
DB::Aowow()->query('UPDATE ?_screenshots SET status = ?d, userIdApprove = ?d WHERE id = ?d', CC_FLAG_APPROVED, User::$id, $id);
Util::gainSiteReputation($_['userIdOwner'], SITEREP_ACTION_UPLOAD, ['id' => $id, 'what' => 1, 'date' => $_['date']]);
// flag DB entry as having screenshots
if (Util::$typeClasses[$_['type']] && ($tbl = (new Util::$typeClasses[$_['type']])::$dataTable))
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_SCREENSHOT, $_['typeId']);
}
}
@@ -237,7 +240,16 @@ class AjaxAdmin extends AjaxHandler
}
// flag as deleted if not aready
$oldEntries = DB::Aowow()->selectCol('SELECT `type` AS ARRAY_KEY, GROUP_CONCAT(typeId) FROM ?_screenshots WHERE id IN (?a) GROUP BY `type`', $this->_get['id']);
DB::Aowow()->query('UPDATE ?_screenshots SET status = ?d, userIdDelete = ?d WHERE id IN (?a)', CC_FLAG_DELETED, User::$id, $this->_get['id']);
// deflag db entry as having screenshots
foreach ($oldEntries as $type => $typeIds)
{
$typeIds = explode(',', $typeIds);
$toUnflag = DB::Aowow()->selectCol('SELECT typeId AS ARRAY_KEY, IF(BIT_OR(`status`) & ?d, 1, 0) AS hasMore FROM ?_screenshots WHERE `type` = ?d AND typeId IN (?a) GROUP BY typeId HAVING hasMore = 0', CC_FLAG_APPROVED, $type, $typeIds);
if ($toUnflag && Util::$typeClasses[$type] && ($tbl = (new Util::$typeClasses[$type])::$dataTable))
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags & ~?d WHERE id IN (?a)', CUSTOM_HAS_SCREENSHOT, array_keys($toUnflag));
}
return '';
}
@@ -249,11 +261,24 @@ class AjaxAdmin extends AjaxHandler
if (!$this->_get['id'] || !$this->_get['typeid'])
return '';
$type = DB::Aowow()->selectCell('SELECT type FROM ?_screenshots WHERE id = ?d', $this->_get['id']);
$id = $this->_get['id'][0];
list($type, $oldTypeId) = array_values(DB::Aowow()->selectRow('SELECT type, typeId FROM ?_screenshots WHERE id = ?d', $id));
$typeId = (int)$this->_get['typeid'];
if (!(new Util::$typeClasses[$type]([['id', $typeId]]))->error)
DB::Aowow()->query('UPDATE ?_screenshots SET typeId = ?d WHERE id = ?d', $typeId, $this->_get['id'][0]);
$tc = new Util::$typeClasses[$type]([['id', $typeId]]);
if (!$tc->error)
{
// move screenshot
DB::Aowow()->query('UPDATE ?_screenshots SET typeId = ?d WHERE id = ?d', $typeId, $id);
// flag target as having screenshot
DB::Aowow()->query('UPDATE '.$tc::$dataTable.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_SCREENSHOT, $typeId);
// deflag source for having had screenshots (maybe)
$ssInfo = DB::Aowow()->selectRow('SELECT IF(BIT_OR(~status) & ?d, 1, 0) AS hasMore FROM ?_screenshots WHERE `status`& ?d AND `type` = ?d AND typeId = ?d', CC_FLAG_DELETED, CC_FLAG_APPROVED, $type, $oldTypeId);
if($ssInfo || !$ssInfo['hasMore'])
DB::Aowow()->query('UPDATE '.$tc::$dataTable.' SET cuFlags = cuFlags & ~?d WHERE id = ?d', CUSTOM_HAS_SCREENSHOT, $oldTypeId);
}
return '';
}

View File

@@ -92,8 +92,8 @@ class AjaxComment extends AjaxHandler
// every comment starts with a rating of +1 and i guess the simplest thing to do is create a db-entry with the system as owner
DB::Aowow()->query('INSERT INTO ?_comments_rates (commentId, userId, value) VALUES (?d, 0, 1)', $postIdx);
// flag target with hasComment (if filtrable)
if ($tbl = Util::getCCTableParent($this->_get['type']))
// flag target with hasComment
if (Util::$typeClasses[$this->_get['type']] && ($tbl = (new Util::$typeClasses[$this->_get['type']])::$dataTable))
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $this->_get['typeid']);
}
}
@@ -143,7 +143,7 @@ class AjaxComment extends AjaxHandler
User::isInGroup(U_GROUP_MODERATOR) ? DBSIMPLE_SKIP : User::$id
);
// deflag hasComment (if filtrable)
// deflag hasComment
if ($ok)
{
$coInfo = DB::Aowow()->selectRow('SELECT IF(BIT_OR(~b.flags) & ?d, 1, 0) as hasMore, b.type, b.typeId FROM ?_comments a JOIN ?_comments b ON a.type = b.type AND a.typeId = b.typeId WHERE a.id = ?d',
@@ -151,7 +151,7 @@ class AjaxComment extends AjaxHandler
$this->_post['id']
);
if (!$coInfo['hasMore'] && ($tbl = Util::getCCTableParent($coInfo['type'])))
if (!$coInfo['hasMore'] && Util::$typeClasses[$coInfo['type']] && ($tbl = (new Util::$typeClasses[$coInfo['type']])::$dataTable))
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags & ~?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $coInfo['typeId']);
}
}
@@ -168,11 +168,11 @@ class AjaxComment extends AjaxHandler
User::isInGroup(U_GROUP_MODERATOR) ? DBSIMPLE_SKIP : User::$id
);
// reflag hasComment (if filtrable)
// reflag hasComment
if ($ok)
{
$coInfo = DB::Aowow()->selectRow('SELECT type, typeId FROM ?_comments WHERE id = ?d', $this->_post['id']);
if ($tbl = Util::getCCTableParent($coInfo['type']))
if (Util::$typeClasses[$coInfo['type']] && ($tbl = (new Util::$typeClasses[$coInfo['type']])::$dataTable))
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $coInfo['typeId']);
}
}

View File

@@ -50,14 +50,14 @@ abstract class BaseType
* results in
* WHERE ((`id` = 45) OR (`name` NOT LIKE "test%") OR ((`flags` & 255) AND (`flags2` & 15)) OR ((`mask` & 3) = 0)) OR (`joinedTbl`.`field` IS NULL) LIMIT 5
*/
public function __construct($conditions = [], $miscData = null)
public function __construct(array $conditions = [], $miscData = null)
{
$where = [];
$linking = ' AND ';
$limit = CFG_SQL_LIMIT_DEFAULT;
$className = get_class($this);
if (!$this->queryBase || $conditions === null)
if (!$this->queryBase || !$conditions)
return;
$prefixes = [];

View File

@@ -10,6 +10,7 @@ class AchievementList extends BaseType
public static $type = TYPE_ACHIEVEMENT;
public static $brickFile = 'achievement';
public static $dataTable = '?_achievement';
public $criteria = [];

View File

@@ -8,6 +8,7 @@ class CharClassList extends BaseType
{
public static $type = TYPE_CLASS;
public static $brickFile = 'class';
public static $dataTable = '?_classes';
protected $queryBase = 'SELECT *, id AS ARRAY_KEY FROM ?_classes c';

View File

@@ -8,6 +8,7 @@ class CharRaceList extends BaseType
{
public static $type = TYPE_RACE;
public static $brickFile = 'race';
public static $dataTable = '?_races';
protected $queryBase = 'SELECT *, id AS ARRAY_KEY FROM ?_races r';

View File

@@ -10,6 +10,7 @@ class CreatureList extends BaseType
public static $type = TYPE_NPC;
public static $brickFile = 'creature';
public static $dataTable = '?_creature';
protected $queryBase = 'SELECT ct.*, ct.id AS ARRAY_KEY FROM ?_creature ct';
public $queryOpts = array(

View File

@@ -8,6 +8,7 @@ class CurrencyList extends BaseType
{
public static $type = TYPE_CURRENCY;
public static $brickFile = 'currency';
public static $dataTable = '?_currencies';
protected $queryBase = 'SELECT *, c.id AS ARRAY_KEY FROM ?_currencies c';
protected $queryOpts = array(

View File

@@ -8,6 +8,7 @@ class EmoteList extends BaseType
{
public static $type = TYPE_EMOTE;
public static $brickFile = 'emote';
public static $dataTable = '?_emotes';
protected $queryBase = 'SELECT *, e.id AS ARRAY_KEY FROM ?_emotes e';

View File

@@ -10,6 +10,7 @@ class EnchantmentList extends BaseType
public static $type = TYPE_ENCHANTMENT;
public static $brickFile = 'enchantment';
public static $dataTable = '?_itemenchantment';
private $jsonStats = [];
private $relSpells = [];

View File

@@ -8,6 +8,7 @@ class FactionList extends BaseType
{
public static $type = TYPE_FACTION;
public static $brickFile = 'faction';
public static $dataTable = '?_factions';
protected $queryBase = 'SELECT f.*, f.parentFactionId AS cat, f.id AS ARRAY_KEY FROM ?_factions f';
protected $queryOpts = array(

View File

@@ -10,6 +10,7 @@ class GameObjectList extends BaseType
public static $type = TYPE_OBJECT;
public static $brickFile = 'object';
public static $dataTable = '?_objects';
protected $queryBase = 'SELECT o.*, o.id AS ARRAY_KEY FROM ?_objects o';
protected $queryOpts = array(

View File

@@ -10,6 +10,7 @@ class ItemList extends BaseType
public static $type = TYPE_ITEM;
public static $brickFile = 'item';
public static $dataTable = '?_items';
public $json = [];
public $itemMods = [];
@@ -1792,7 +1793,7 @@ class ItemListFilter extends Filter
public function __construct()
{
$classes = new CharClassList();
$classes = new CharClassList([true]);
foreach ($classes->iterate() as $cId => $_tpl)
{
// preselect misc subclasses

View File

@@ -10,6 +10,7 @@ class ItemsetList extends BaseType
public static $type = TYPE_ITEMSET;
public static $brickFile = 'itemset';
public static $dataTable = '?_itemset';
public $pieceToSet = []; // used to build g_items and search
private $classes = []; // used to build g_classes

View File

@@ -10,6 +10,7 @@ class PetList extends BaseType
public static $type = TYPE_PET;
public static $brickFile = 'pet';
public static $dataTable = '?_pet';
protected $queryBase = 'SELECT *, id AS ARRAY_KEY FROM ?_pet p';

View File

@@ -11,6 +11,7 @@ class ProfileList extends BaseType
{
public static $type = 0; // profiles dont actually have one
public static $brickFile = 'profile';
public static $dataTable = ''; // doesn't have community content
protected $queryBase = ''; // SELECT p.*, p.id AS ARRAY_KEY FROM ?_profiles p';
protected $queryOpts = array(

View File

@@ -8,6 +8,7 @@ class QuestList extends BaseType
{
public static $type = TYPE_QUEST;
public static $brickFile = 'quest';
public static $dataTable = '?_quests';
public $requires = [];
public $rewards = [];

View File

@@ -8,6 +8,7 @@ class SkillList extends BaseType
{
public static $type = TYPE_SKILL;
public static $brickFile = 'skill';
public static $dataTable = '?_skillline';
protected $queryBase = 'SELECT *, sl.id AS ARRAY_KEY FROM ?_skillline sl';
protected $queryOpts = array(

View File

@@ -14,6 +14,7 @@ class SpellList extends BaseType
public static $type = TYPE_SPELL;
public static $brickFile = 'spell';
public static $dataTable = '?_spell';
public static $skillLines = array(
6 => [ 43, 44, 45, 46, 54, 55, 95, 118, 136, 160, 162, 172, 173, 176, 226, 228, 229, 473], // Weapons

View File

@@ -10,6 +10,7 @@ class TitleList extends BaseType
public static $type = TYPE_TITLE;
public static $brickFile = 'title';
public static $dataTable = '?_titles';
public $sources = [];

View File

@@ -8,6 +8,7 @@ class UserList extends BaseType
{
public static $type = TYPE_USER;
public static $brickFile = 'user';
public static $dataTable = ''; // doesn't have community content
public $sources = [];

View File

@@ -8,6 +8,7 @@ class WorldEventList extends BaseType
{
public static $type = TYPE_WORLDEVENT;
public static $brickFile = 'event';
public static $dataTable = '?_events';
protected $queryBase = 'SELECT e.*, h.*, e.description AS nameINT, e.id AS id, e.id AS ARRAY_KEY FROM ?_events e';
protected $queryOpts = array(

View File

@@ -10,6 +10,7 @@ class ZoneList extends BaseType
public static $type = TYPE_ZONE;
public static $brickFile = 'zone';
public static $dataTable = '?_zones';
protected $queryBase = 'SELECT *, id AS ARRAY_KEY FROM ?_zones z';

View File

@@ -1430,23 +1430,6 @@ class Util
return DB::Aowow()->query('INSERT IGNORE INTO ?_account_reputation (?#) VALUES (?a)', array_keys($x), array_values($x));
}
// TYPE => tableName; when handling comments, screenshots or videos
public static function getCCTableParent($type)
{
// only filtrable types; others don't care about being flagged for having CommunityContent
switch ($type)
{
case TYPE_ACHIEVEMENT: return '?_achievement';
case TYPE_SPELL: return '?_spell';
case TYPE_OBJECT: return '?_objects';
case TYPE_ITEM: return '?_items';
case TYPE_ITEMSET: return '?_itemset';
case TYPE_NPC: return '?_creature';
case TYPE_QUEST: return '?_quests';
default: return null;
}
}
public static function getServerConditions($srcType, $srcGroup = null, $srcEntry = null)
{
if (!$srcGroup && !$srcEntry)

View File

@@ -25,7 +25,7 @@ class ClassesPage extends GenericPage
protected function generateContent()
{
$classes = new CharClassList();
$classes = new CharClassList([true]);
if (!$classes->error)
$this->lvTabs[] = ['class', ['data' => array_values($classes->getListviewData())]];
}

View File

@@ -26,7 +26,7 @@ class EmotesPage extends GenericPage
protected function generateContent()
{
$tabData = array(
'data' => array_values((new EmoteList())->getListviewData()),
'data' => array_values((new EmoteList([true]))->getListviewData()),
'name' => Util::ucFirst(Lang::game('emotes'))
);

View File

@@ -559,7 +559,7 @@ class QuestPage extends GenericPage
$this->suggestedPl = $this->subject->getField('suggestedPlayers');
$this->unavailable = $_flags & QUEST_FLAG_UNAVAILABLE || $this->subject->getField('cuFlags') & CUSTOM_EXCLUDE_FOR_LISTVIEW;
$this->redButtons = array(
BUTTON_WOWHEAD => true
BUTTON_WOWHEAD => true,
BUTTON_LINKS => array(
'linkColor' => 'ffffff00',
'linkId' => 'quest:'.$this->typeId.':'.$_level;

View File

@@ -0,0 +1,107 @@
-- TYPE_NPC:1
UPDATE aowow_creature a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 1 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_OBJECT:2
UPDATE aowow_objects a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 2 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_ITEM:3
UPDATE aowow_items a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 3 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_ITEMSET:4
UPDATE aowow_itemset a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 4 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_QUEST:5
UPDATE aowow_quests a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 5 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_SPELL:6
UPDATE aowow_spell a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 6 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_ZONE:7
UPDATE aowow_zones a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 7 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_FACTION:8
UPDATE aowow_factions a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 8 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_PET:9
UPDATE aowow_pet a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 9 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_ACHIEVEMENT:10
UPDATE aowow_achievement a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 10 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_TITLE:11
UPDATE aowow_titles a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 11 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_WORLDEVENT:12
UPDATE aowow_events a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 12 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_CLASS:13
UPDATE aowow_classes a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 13 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_RACE:14
UPDATE aowow_races a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 14 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_SKILL:15
UPDATE aowow_skillline a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 15 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_CURRENCY:17
UPDATE aowow_currencies a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 17 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_EMOTE:501
UPDATE aowow_emotes a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 501 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;
-- TYPE_ENCHANTMENT:502
UPDATE aowow_itemenchantment a
JOIN (SELECT typeId, BIT_OR(`status`) AS `ccFlags` FROM aowow_screenshots WHERE `type` = 502 GROUP BY typeId) b ON a.id = b.typeId
SET a.cuFlags = a.cuFlags | 0x02000000
WHERE b.ccFlags & 0x8;