Пример #1
0
 public function UpdateCounts()
 {
     // Define the necessary SQL.
     $StepSql = array("update :_Discussion d set\r\nLastCommentID = (select max(c.CommentID) from :_Comment c where c.DiscussionID = d.DiscussionID),\r\nCountComments = (select count(c.CommentID) from :_Comment c where c.DiscussionID = d.DiscussionID),\r\nDateLastComment = (select max(c.DateInserted) from :_Comment c where c.DiscussionID = d.DiscussionID)", "update :_Discussion d\r\ninner join :_Comment c\r\n  on c.DiscussionID = d.DiscussionID\r\ninner join (\r\n  select min(c2.CommentID) as CommentID\r\n  from :_Comment c2\r\n  group by c2.DiscussionID\r\n) c2\r\n  on c.CommentID = c2.CommentID\r\nset\r\n  d.Body = c.Body,\r\n  d.Format = c.Format,\r\n  d.FirstCommentID = c.CommentID\r\nwhere d.Body is null", "delete :_Comment c\r\nfrom :_Comment c\r\ninner join :_Discussion d\r\n  on d.FirstCommentID = c.CommentID", "update :_Discussion d\r\njoin :_Comment c\r\n  on d.LastCommentID = c.CommentID\r\nset d.LastCommentUserID = c.InsertUserID", "update :_Category c set\r\nc.CountDiscussions = (select count(d.DiscussionID) from :_Discussion d where d.CategoryID = c.CategoryID)");
     // Add the FirstCommentID to the discussion table.
     Gdn::Structure()->Table('Discussion')->Column('FirstCommentID', 'int', NULL)->Set(FALSE, FALSE);
     // Execute the SQL.
     $CurrentSubstep = GetValue('CurrentSubstep', $this->Data, 0);
     for ($i = $CurrentSubstep; $i < count($StepSql); $i++) {
         $Sql = $StepSql[$i];
         $this->Query($Sql);
         if ($this->Timer->ElapsedTime() > $this->MaxStepTime) {
             $this->Data['CurrentSubstep'] = $i + 1;
             return FALSE;
         }
     }
     if (isset($this->Data['CurrentSubstep'])) {
         unset($this->Data['CurrentSubstep']);
     }
     // Remove the FirstCommentID from the discussion table.
     Gdn::Structure()->Table('Discussion')->DropColumn('FirstCommentID');
     return TRUE;
 }
Пример #2
0
} else {
    $Filename = '';
}
//$Filename = val('OriginalFilename', $this->Data);
if ($Filename) {
    $Header[T('Source')] = $Filename;
}
$Header = array_merge($Header, (array) GetValue('Header', $this->Data, array()));
$Stats = (array) GetValue('Stats', $this->Data, array());
$Info = array_merge($Header, $Stats);
foreach ($Info as $Name => $Value) {
    switch ($Name) {
        case 'Orphaned Comments':
        case 'Orphaned Discussions':
            $Value .= ' ' . anchor(t('Click here to fix.'), Gdn::request()->Url('dba/fixinsertuserid'));
            break;
        default:
            $Name = htmlspecialchars($Name);
            $Value = htmlspecialchars($Value);
            if (substr_compare('Time', $Name, 0, 4, true) == 0) {
                $Value = Gdn_Timer::FormatElapsed($Value);
            }
    }
    echo "<tr><th>{$Name}</th><td class=\"Alt\">{$Value}</td></tr>\n";
}
if ($this->data('GenerateSQL')) {
    echo "<tr><th>" . t('Special') . "</th><td class=\"Alt\">" . t('Generate import SQL only') . "</td></tr>\n";
}
?>
</table>
Пример #3
0
 public function InsertTables()
 {
     $InsertedCount = 0;
     $Timer = new Gdn_Timer();
     $Timer->Start();
     $Tables =& $this->Tables();
     foreach ($Tables as $TableName => $TableInfo) {
         if (GetValue('Inserted', $TableInfo) || GetValue('Skip', $TableInfo)) {
             $InsertedCount++;
         } else {
             $this->Data['CurrentStepMessage'] = sprintf(T('%s of %s'), $InsertedCount, count($Tables));
             if (strcasecmp($this->Overwrite(), 'Overwrite') == 0) {
                 switch ($TableName) {
                     case 'Permission':
                         $this->InsertPermissionTable();
                         break;
                     default:
                         $RowCount = $this->_InsertTable($TableName);
                         break;
                 }
             } else {
                 switch ($TableName) {
                     case 'Permission':
                         $this->InsertPermissionTable();
                         break;
                     case 'UserDiscussion':
                         $Sql = "insert ignore :_UserDiscussion ( UserID, DiscussionID, DateLastViewed, Bookmarked )\r\n                        select zUserID._NewID, zDiscussionID._NewID, max(i.DateLastViewed) as DateLastViewed, max(i.Bookmarked) as Bookmarked\r\n                        from :_zUserDiscussion i\r\n                        left join :_zUser zUserID\r\n                          on i.UserID = zUserID.UserID\r\n                        left join :_zDiscussion zDiscussionID\r\n                          on i.DiscussionID = zDiscussionID.DiscussionID\r\n                        left join :_UserDiscussion ud\r\n                          on ud.UserID = zUserID._NewID and ud.DiscussionID = zDiscussionID._NewID\r\n                        where ud.UserID is null\r\n                        group by zUserID._NewID, zDiscussionID._NewID";
                         $this->Query($Sql);
                         break;
                     case 'UserMeta':
                         $Sql = "insert ignore :_UserMeta ( UserID, Name, Value )\r\n                           select zUserID._NewID, i.Name, max(i.Value) as Value\r\n                           from :_zUserMeta i\r\n                           left join :_zUser zUserID\r\n                             on i.UserID = zUserID.UserID\r\n                           left join :_UserMeta um\r\n                             on zUserID._NewID = um.UserID and i.Name = um.Name\r\n                           where um.UserID is null\r\n                           group by zUserID._NewID, i.Name";
                         $this->Query($Sql);
                         break;
                     case 'UserRole':
                         $Sql = "insert ignore :_UserRole ( UserID, RoleID )\r\n                           select zUserID._NewID, zRoleID._NewID\r\n                           from :_zUserRole i\r\n                           left join :_zUser zUserID\r\n                             on i.UserID = zUserID.UserID\r\n                           left join :_zRole zRoleID\r\n                             on i.RoleID = zRoleID.RoleID\r\n                           left join :_UserRole ur\r\n                              on zUserID._NewID = ur.UserID and zRoleID._NewID = ur.RoleID\r\n                           where i.UserID <> 0 and ur.UserID is null";
                         $this->Query($Sql);
                         break;
                     default:
                         $RowCount = $this->_InsertTable($TableName);
                 }
             }
             $Tables[$TableName]['Inserted'] = TRUE;
             if (isset($RowCount)) {
                 $Tables[$TableName]['RowCount'] = $RowCount;
             }
             $InsertedCount++;
             // Make sure the loading isn't taking too long.
             if ($Timer->ElapsedTime() > $this->MaxStepTime) {
                 break;
             }
         }
     }
     $Result = $InsertedCount == count($this->Tables());
     if ($Result) {
         $this->Data['CurrentStepMessage'] = '';
     }
     return $Result;
 }