1 | <?php |
||
18 | class IndexDBReader { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $tables; |
||
23 | |||
24 | /** |
||
25 | * Lists of fields that contain an id. |
||
26 | * |
||
27 | * @var array<string,int> |
||
28 | */ |
||
29 | protected $id_fields; |
||
30 | |||
31 | /** |
||
32 | * List of all fields that contain an integer. |
||
33 | * |
||
34 | * @var array<string,0> |
||
35 | */ |
||
36 | protected $int_fields; |
||
37 | |||
38 | /** |
||
39 | * @var \Closure |
||
40 | */ |
||
41 | protected $get_query_builder; |
||
42 | |||
43 | /** |
||
44 | * @var Insert |
||
45 | */ |
||
46 | protected $other; |
||
47 | |||
48 | /** |
||
49 | * @var array<int|null,mixed>|null |
||
50 | */ |
||
51 | protected $id_map = null; |
||
52 | |||
53 | /** |
||
54 | * @var array|null |
||
55 | */ |
||
56 | protected $results = null; |
||
57 | |||
58 | /** |
||
59 | * @var bool |
||
60 | */ |
||
61 | protected $already_run; |
||
62 | |||
63 | /** |
||
64 | * @param array $tables list of tables and fields according to IndexDB |
||
65 | * @param array $id_fields list of fields that contain a id |
||
66 | * @param array $int_fields list of fields that contain an int |
||
67 | * @param \Closure $get_query_builder to get a QueryBuilder |
||
68 | */ |
||
69 | 1 | public function __construct($tables, $id_fields, $int_fields, \Closure $get_query_builder, Insert $insert) { |
|
77 | |||
78 | |||
79 | /** |
||
80 | * Read the index from the database and put it to insert. |
||
81 | */ |
||
82 | 1 | public function run() { |
|
93 | |||
94 | /** |
||
95 | * Builds a list of inserts ordered by the id. |
||
96 | * |
||
97 | * @return \Iterator $table => $values |
||
98 | */ |
||
99 | 1 | protected function get_inserts() { |
|
140 | |||
141 | /** |
||
142 | * Initialize all tables that contain an id with their results. |
||
143 | * |
||
144 | * @return array[] containing [$table_name, null, $results] |
||
145 | */ |
||
146 | 1 | protected function build_results_with_id() { |
|
156 | |||
157 | /** |
||
158 | * @param string $table |
||
159 | * @return \Iterator |
||
160 | */ |
||
161 | 1 | protected function select_all_from($table) { |
|
168 | |||
169 | /** |
||
170 | * Transforms results as retreived from sql to their appropriate internal |
||
171 | * representation. |
||
172 | * |
||
173 | * TODO: Unrolling this loop might make things faster. |
||
174 | * |
||
175 | * @param array &$results from database |
||
176 | * @return array |
||
177 | */ |
||
178 | 1 | protected function transform_results(array &$results) { |
|
188 | |||
189 | /** |
||
190 | * @param \Iterator $inserts |
||
191 | * @return null |
||
192 | */ |
||
193 | 1 | protected function write_inserts(\Iterator $inserts) { |
|
207 | } |
||
208 |