protected function reassignDocuments()
    {
        $countCheck = SQLSelect::create('*', 'DMSDocument_Pages');
        if (!$countCheck->count()) {
            $this->output('There was no data to migrate. Finishing.');
            return $this;
        }

        $query = SQLSelect::create(array('DMSDocumentID', 'SiteTreeID'), 'DMSDocument_Pages');
        $result = $query->execute();

        foreach ($result as $row) {
            $document = DMSDocument::get()->byId($row['DMSDocumentID']);
            if (!$document) {
                $this->addResult('Skipped: document does not exist');
                continue;
            }

            $page = SiteTree::get()->byId($row['SiteTreeID']);
            if (!$page) {
                $this->addResult('Skipped: page does not exist');
                continue;
            }

            // Don't try and process pages that don't have a document set. This should be created by the first
            // action step in this build task, so shouldn't occur if run in correct order.
            if (!$page->DocumentSets()->count()) {
                $this->addResult('Skipped: no default document set');
                continue;
            }
            $this->addDocumentToSet($document, $page->DocumentSets()->first());
            $this->addResult('Reassigned to document set');
        }

        return $this;
    }