/** * Run the step in the import. * @param int $Step the step to run. * @return mixed Whether the step succeeded or an array of information. */ public function RunStep($Step = 1) { $Steps = $this->Steps(); if ($Step > count($Steps)) { return 'COMPLETE'; } if (!$this->Timer) { $NewTimer = TRUE; $this->Timer = new Gdn_Timer(); $this->Timer->Start(''); } $Method = $Steps[$Step]; $Result = call_user_method($Method, $this); if (isset($NewTimer)) { $this->Timer->Finish(''); } return $Result; }
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; }