Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TopicIterator | |
0.00% |
0 / 16 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| query | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| transform | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Flow\Search\Iterators; |
| 4 | |
| 5 | use Flow\DbFactory; |
| 6 | use Flow\Model\PostRevision; |
| 7 | use Flow\Model\UUID; |
| 8 | use Flow\Repository\RootPostLoader; |
| 9 | use stdClass; |
| 10 | |
| 11 | class TopicIterator extends AbstractIterator { |
| 12 | /** |
| 13 | * @var PostRevision |
| 14 | */ |
| 15 | protected $previous; |
| 16 | |
| 17 | /** |
| 18 | * @var RootPostLoader |
| 19 | */ |
| 20 | protected $rootPostLoader; |
| 21 | |
| 22 | /** |
| 23 | * @var bool |
| 24 | */ |
| 25 | public $orderByUUID = false; |
| 26 | |
| 27 | public function __construct( DbFactory $dbFactory, RootPostLoader $rootPostLoader ) { |
| 28 | parent::__construct( $dbFactory ); |
| 29 | $this->rootPostLoader = $rootPostLoader; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Instead of querying for revisions (which is what we actually need), we'll |
| 34 | * just query the workflow table, which will save us some complicated joins. |
| 35 | * The workflow_id for a topic title (aka root post) is the same as its |
| 36 | * collection id, so we can pass that to the root post loader and *poof*, we |
| 37 | * have our revisions! |
| 38 | * |
| 39 | * @inheritDoc |
| 40 | */ |
| 41 | protected function query() { |
| 42 | if ( $this->orderByUUID ) { |
| 43 | $order = 'workflow_id'; |
| 44 | } else { |
| 45 | $order = 'workflow_last_update_timestamp'; |
| 46 | } |
| 47 | return $this->dbr->newSelectQueryBuilder() |
| 48 | // for root post (topic title), workflow_id is the same as its rev_type_id |
| 49 | ->select( [ 'workflow_id', 'workflow_last_update_timestamp' ] ) |
| 50 | ->from( 'flow_workflow' ) |
| 51 | ->where( [ 'workflow_type' => 'topic' ] ) |
| 52 | ->andWhere( $this->conditions ) |
| 53 | ->orderBy( $order ) |
| 54 | ->caller( __METHOD__ ) |
| 55 | ->fetchResultSet(); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @inheritDoc |
| 60 | */ |
| 61 | protected function transform( stdClass $row ) { |
| 62 | $root = UUID::create( $row->workflow_id ); |
| 63 | |
| 64 | // we need to fetch all data via rootloader because we'll want children |
| 65 | // to be populated |
| 66 | return $this->rootPostLoader->get( $root ); |
| 67 | } |
| 68 | } |