* Add the new version.
This commit is contained in:
@@ -552,6 +552,9 @@ class upgradeModel extends model
|
||||
$this->updateStoryFile();
|
||||
$this->convertTaskteam();
|
||||
$this->convertEstToEffort();
|
||||
$this->xuanSetOwnedByForGroups();
|
||||
$this->xuanRecoverCreatedDates();
|
||||
$this->xuanSetPartitionedMessageIndex();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1018,6 +1021,8 @@ class upgradeModel extends model
|
||||
$confirmContent .= file_get_contents($this->getUpgradeFile('17.4'));
|
||||
case '17_5':
|
||||
$confirmContent .= file_get_contents($this->getUpgradeFile('17.5'));
|
||||
case '17_6':
|
||||
$confirmContent .= file_get_contents($this->getUpgradeFile('17.6'));
|
||||
}
|
||||
|
||||
return $confirmContent;
|
||||
@@ -7350,4 +7355,138 @@ class upgradeModel extends model
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Xuan: Set ownedBy for group chats without it.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function xuanSetOwnedByForGroups()
|
||||
{
|
||||
$this->dao->update(TABLE_IM_CHAT)->set('ownedBy = createdBy')->where('ownedBy')->eq('')->exec();
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Xuan: Recover created date for chats.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function xuanRecoverCreatedDates()
|
||||
{
|
||||
$chats = $this->dao->select('gid, id')->from(TABLE_IM_CHAT)
|
||||
->where('createdDate')->eq('0000-00-00 00:00:00')
|
||||
->fetchPairs('gid');
|
||||
|
||||
$createdDateData = array();
|
||||
|
||||
/* Try query earliest message date indexed. */
|
||||
$indexedMinDates = $this->dao->select('gid, MIN(startDate)')->from(TABLE_IM_CHAT_MESSAGE_INDEX)
|
||||
->where('gid')->in(array_keys($chats))
|
||||
->groupBy('gid')
|
||||
->fetchPairs('gid');
|
||||
|
||||
/* Then try query earliest message date non-indexed from master table. */
|
||||
$queryChats = array_diff(array_keys($chats), array_keys($indexedMinDates));
|
||||
$minDates = $this->dao->select('cgid, MIN(date)')->from(TABLE_IM_MESSAGE)
|
||||
->where('cgid')->in($queryChats)
|
||||
->groupBy('cgid')
|
||||
->fetchPairs('cgid');
|
||||
|
||||
$knownMinDates = array_merge($indexedMinDates, $minDates);
|
||||
|
||||
$remainingChats = $chats;
|
||||
foreach($chats as $cgid => $cid)
|
||||
{
|
||||
if(isset($knownMinDates[$cgid]))
|
||||
{
|
||||
$createdDateData[$cid] = $knownMinDates[$cgid];
|
||||
unset($remainingChats[$cgid]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Use other dates for chats without messages. */
|
||||
$chatDates = $this->dao->select('id, gid, editedDate, lastActiveTime, dismissDate')->from(TABLE_IM_CHAT)
|
||||
->where('gid')->in(array_keys($remainingChats))
|
||||
->fetchAll('gid');
|
||||
$chatDates = array_map(function($chatDate)
|
||||
{
|
||||
$dates = array_filter(array($chatDate->editedDate, $chatDate->lastActiveTime, $chatDate->dismissDate), function($date)
|
||||
{
|
||||
return $date != '0000-00-00 00:00:00';
|
||||
});
|
||||
$minDate = min($dates);
|
||||
return $minDate;
|
||||
}, $chatDates);
|
||||
|
||||
$knownMinDates = array_merge($knownMinDates, $chatDates);
|
||||
|
||||
$queryData = array();
|
||||
foreach($knownMinDates as $gid => $date) $queryData[] = "WHEN {$chats[$gid]} THEN '{$date}'";
|
||||
|
||||
$query = "UPDATE " . TABLE_IM_CHAT . " SET `createdDate` = (CASE `id` " . join(' ', $queryData) . " END) WHERE `id` IN(" . join(",", array_values($chats)) . ");";
|
||||
$this->dao->query($query);
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Xuan: Set index range for chats in chat partition index table.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function xuanSetPartitionedMessageIndex()
|
||||
{
|
||||
ini_set('memory_limit', '1024M');
|
||||
set_time_limit(0);
|
||||
|
||||
/* Fetch chat and message partition table associations with message range. */
|
||||
$chatTableData = $this->dao->select('gid, tableName, start, end')->from(TABLE_IM_CHAT_MESSAGE_INDEX)
|
||||
->where('startIndex')->eq(0)
|
||||
->orWhere('endIndex')->eq(0)
|
||||
->orderBy('id_asc')
|
||||
->fetchAll();
|
||||
|
||||
/* Sort ranges by table. */
|
||||
$tableRanges = array();
|
||||
foreach($chatTableData as $chatTable)
|
||||
{
|
||||
if(isset($tableRanges[$chatTable->tableName]))
|
||||
{
|
||||
$tableRanges[$chatTable->tableName]->start[] = $chatTable->start;
|
||||
$tableRanges[$chatTable->tableName]->end[] = $chatTable->end;
|
||||
continue;
|
||||
}
|
||||
$tableRanges[$chatTable->tableName] = (object)array('start' => array($chatTable->start), 'end' => array($chatTable->end));
|
||||
}
|
||||
|
||||
/* Query corresponding message indice. */
|
||||
foreach($tableRanges as $tableName => $tableRange)
|
||||
{
|
||||
$ids = array_merge($tableRange->start, $tableRange->end);
|
||||
$ids = array_unique($ids);
|
||||
$indexPairs = $this->dao->select('id, `index`')->from("`$tableName`")
|
||||
->where('id')->in($ids)
|
||||
->fetchPairs('id');
|
||||
$tableRanges[$tableName]->indexPairs = $indexPairs;
|
||||
}
|
||||
|
||||
/* Set startIndice and endIndice. */
|
||||
foreach($tableRanges as $tableRange)
|
||||
{
|
||||
$queryData = array();
|
||||
foreach($tableRange->start as $id) $queryData[] = "WHEN $id THEN {$tableRange->indexPairs[$id]}";
|
||||
$query = "UPDATE " . TABLE_IM_CHAT_MESSAGE_INDEX . " SET `startIndex` = (CASE `start` " . join(' ', $queryData) . " END) WHERE `start` IN(" . join(',', $tableRange->start) . ");";
|
||||
$this->dao->query($query);
|
||||
|
||||
$queryData = array();
|
||||
foreach($tableRange->end as $id) $queryData[] = "WHEN $id THEN {$tableRange->indexPairs[$id]}";
|
||||
$query = "UPDATE " . TABLE_IM_CHAT_MESSAGE_INDEX . " SET `endIndex` = (CASE `end` " . join(' ', $queryData) . " END) WHERE `end` IN(" . join(',', $tableRange->end) . ");";
|
||||
$this->dao->query($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user