Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| PostRevisionTopicHistoryStorage | |
0.00% |
0 / 22 |
|
0.00% |
0 / 9 |
156 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| find | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| findMulti | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| findDescendantQuery | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| getPrimaryKeyColumns | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| insert | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| remove | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| validate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Flow\Data\Storage; |
| 4 | |
| 5 | use Flow\Data\ObjectStorage; |
| 6 | use Flow\Exception\DataModelException; |
| 7 | use Flow\Model\UUID; |
| 8 | use Flow\Repository\TreeRepository; |
| 9 | |
| 10 | /** |
| 11 | * Query-only storage implementation provides history of all post revisions in a topic. |
| 12 | */ |
| 13 | class PostRevisionTopicHistoryStorage implements ObjectStorage { |
| 14 | |
| 15 | /** |
| 16 | * @var ObjectStorage |
| 17 | */ |
| 18 | protected $postRevisionStorage; |
| 19 | |
| 20 | /** |
| 21 | * @var TreeRepository |
| 22 | */ |
| 23 | protected $treeRepository; |
| 24 | |
| 25 | public function __construct( ObjectStorage $postRevisionStorage, TreeRepository $treeRepo ) { |
| 26 | $this->postRevisionStorage = $postRevisionStorage; |
| 27 | $this->treeRepository = $treeRepo; |
| 28 | } |
| 29 | |
| 30 | public function find( array $attributes, array $options = [] ) { |
| 31 | $multi = $this->findMulti( [ $attributes ], $options ); |
| 32 | return $multi ? reset( $multi ) : []; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * This is called with queries for 'topic_root_id': a "virtual" column that we'll |
| 37 | * interpret. Based on these root ids (=topic id), we'll fetch all post revisions inside |
| 38 | * that topic. |
| 39 | * @param array $queries |
| 40 | * @param array $options |
| 41 | * @return array |
| 42 | */ |
| 43 | public function findMulti( array $queries, array $options = [] ) { |
| 44 | foreach ( $queries as $idx => $query ) { |
| 45 | if ( isset( $query['topic_root_id'] ) ) { |
| 46 | $descendantQuery = $this->findDescendantQuery( $query ); |
| 47 | unset( $query['topic_root_id'] ); |
| 48 | $queries[$idx] = array_merge( $query, $descendantQuery ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return $this->postRevisionStorage->findMulti( $queries, $options ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * All queries are for roots (guaranteed in findMulti), so anything that falls |
| 57 | * through and has to be queried from storage will actually need to be doing a |
| 58 | * special condition either joining against flow_tree_node or first collecting the |
| 59 | * subtree node lists and then doing a big IN condition |
| 60 | * |
| 61 | * This isn't a hot path (should be pre-populated into index) but we still don't want |
| 62 | * horrible performance |
| 63 | * |
| 64 | * @param array $query |
| 65 | * @return array |
| 66 | * @throws \Flow\Exception\InvalidInputException |
| 67 | */ |
| 68 | protected function findDescendantQuery( array $query ) { |
| 69 | $roots = [ UUID::create( $query['topic_root_id'] ) ]; |
| 70 | $nodeList = $this->treeRepository->fetchSubtreeNodeList( $roots ); |
| 71 | |
| 72 | /** @var UUID $topicRootId */ |
| 73 | $topicRootId = UUID::create( $query['topic_root_id'] ); |
| 74 | $nodes = $nodeList[$topicRootId->getAlphadecimal()]; |
| 75 | return [ |
| 76 | 'rev_type_id' => UUID::convertUUIDs( $nodes ), |
| 77 | ]; |
| 78 | } |
| 79 | |
| 80 | public function getPrimaryKeyColumns() { |
| 81 | return [ 'topic_root_id' ]; |
| 82 | } |
| 83 | |
| 84 | public function insert( array $row ) { |
| 85 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod LSP violation. |
| 86 | throw new DataModelException( __CLASS__ . ' does not support insert action', 'process-data' ); |
| 87 | } |
| 88 | |
| 89 | public function update( array $old, array $new ) { |
| 90 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod LSP violation. |
| 91 | throw new DataModelException( __CLASS__ . ' does not support update action', 'process-data' ); |
| 92 | } |
| 93 | |
| 94 | public function remove( array $row ) { |
| 95 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod LSP violation. |
| 96 | throw new DataModelException( __CLASS__ . ' does not support remove action', 'process-data' ); |
| 97 | } |
| 98 | |
| 99 | public function validate( array $row ) { |
| 100 | return true; |
| 101 | } |
| 102 | } |