function sourceRecords($params, $sort, $limit) { $cachekey = md5(serialize($params)); if (!isset($this->_cache_sourceRecords[$cachekey])) { $res = WorkflowThreeStepRequest::get_by_approver('WorkflowPublicationRequest', Member::currentUser(), array('AwaitingApproval')); $doSet = new DataObjectSet(); if ($res) { foreach ($res as $result) { if ($wf = $result->openWorkflowRequest()) { if (ClassInfo::exists('Subsite')) { $result->SubsiteTitle = $result->Subsite()->Title; } $result->RequestedAt = $wf->Created; $result->WFAuthorTitle = $wf->Author()->Title; $result->HasEmbargo = $wf->getEmbargoDate(); $doSet->push($result); } } } $this->_cache_sourceRecords[$cachekey] = $doSet; } $doSet = $this->_cache_sourceRecords[$cachekey]; if ($sort) { $parts = explode(' ', $sort); $field = $parts[0]; $direction = $parts[1]; if ($field == 'AbsoluteLink') { $sort = 'URLSegment ' . $direction; } if ($field == 'Subsite.Title') { $sort = 'SubsiteID ' . $direction; } $doSet->sort($sort); } if ($limit && $limit['limit']) { return $doSet->getRange($limit['start'], $limit['limit']); } else { return $doSet; } }
function sourceRecords($params, $sort, $limit) { increase_time_limit_to(120); $res = WorkflowThreeStepRequest::get_by_approver('WorkflowDeletionRequest', Member::currentUser(), array('AwaitingApproval')); $doSet = new DataObjectSet(); if ($res) { foreach ($res as $result) { if ($wf = $result->openWorkflowRequest()) { $result->WFAuthorTitle = $wf->Author()->Title; $result->WFAuthorID = $wf->AuthorID; $result->WFRequestedWhen = $wf->Created; $result->WFApproverID = $wf->ApproverID; $result->WFPublisherID = $wf->PublisherID; $result->BacklinkCount = $result->BackLinkTracking()->Count(); $doSet->push($result); } } } if ($sort) { $parts = explode(' ', $sort); $field = $parts[0]; $direction = $parts[1]; if ($field == 'AbsoluteLink') { $sort = 'URLSegment ' . $direction; } if ($field == 'Subsite.Title') { $sort = 'SubsiteID ' . $direction; } $doSet->sort($sort); } if ($limit && $limit['limit']) { return $doSet->getRange($limit['start'], $limit['limit']); } else { return $doSet; } }
function testWorkflowPublicationApprovalTransition() { WorkflowRequest::$enable_all_alerts = true; $page = $this->objFromFixture('SiteTree', 'custompublisherpage'); $custompublisher = $this->objFromFixture('Member', 'custompublisher'); $customapprover = $this->objFromFixture('Member', 'customapprover'); $customauthor = $this->objFromFixture('Member', 'customauthor'); // nothing -> awaiting approval $customauthor->logIn(); $request = $page->openOrNewWorkflowRequest('WorkflowPublicationRequest'); $request->request("ARGGGGG!"); $this->assertNotNull($request); $this->assertEquals($request->AuthorID, $customauthor->ID, "Logged-in member is set as the author of the request"); $this->assertEquals($request->Status, 'AwaitingApproval', "Request is set to AwaitingApproval after requestPublication() is called"); // awaiting approval -> approved $customapprover->logIn(); $request->approve('Looks good'); $this->assertEquals($request->Status, 'Approved', "Request is set to Approved after page is approved"); $this->assertEquals($request->ApproverID, $customapprover->ID, "Currently logged-in user is set as the Approver for this request"); // place comment $customauthor->logIn(); $request->comment("YARRRRRR!"); // approved -> completed $custompublisher->logIn(); $request->publish('Avast, ye scoundrels!', $custompublisher, false); $this->assertEquals($request->Status, 'Completed', "Request is set to Completed after page is published"); $this->assertEquals($request->PublisherID, $custompublisher->ID, "Currently logged-in user is set as the Publisher for this request"); // Test save and publish $this->objFromFixture('Member', 'admin')->logIn(); $this->assertTrue(is_string($page->openOrNewWorkflowRequest('WorkflowPublicationRequest')->saveAndPublish("S&P"))); // Test the get_by_* functions. These are cursory tests, covering functionality // but none of the multitude of edge cases $this->assertContains($page->ID, WorkflowThreeStepRequest::get_by_author('WorkflowPublicationRequest', $customauthor)->column('ID')); $this->assertContains($page->ID, WorkflowThreeStepRequest::get_by_approver('WorkflowPublicationRequest', $customapprover)->column('ID')); $this->assertContains($page->ID, WorkflowThreeStepRequest::get_by_publisher('WorkflowPublicationRequest', $custompublisher)->column('ID')); }