Lines Matching refs:this

16  * Note: even though data tables use a data_ prefix in the database, this prefix is internal only and should
37 * @var Schema the previously valid schema for this table
50 /** @var int the time for which this schema should be created - default to time() can be overriden for tests */
64 $this->table = $table;
65 $this->data = $data;
66 $this->oldschema = new Schema($table, 0);
68 $this->helper = plugin_load('helper', 'struct_db');
69 $this->sqlite = $this->helper->getDB();
70 $this->user = $_SERVER['REMOTE_USER'] ?? '';
76 * @param int $time when to create this schema 0 for now
81 $this->time = $time;
82 $this->fixLabelUniqueness();
84 $this->sqlite->query('BEGIN TRANSACTION');
87 if (!$this->oldschema->getId()) {
88 $ok = $this->newDataTable();
92 $ok = $ok && $this->newSchema();
95 $ok = $ok && $this->updateColumns();
96 $ok = $ok && $this->addColumns();
99 $this->sqlite->query('ROLLBACK TRANSACTION');
102 $this->sqlite->query('COMMIT TRANSACTION');
104 return (int)$this->newschemaid;
114 if (isset($this->data['cols'])) foreach ($this->data['cols'] as $idx => $column) {
115 $this->data['cols'][$idx]['label'] = $this->fixLabel($column['label'], $labels);
118 if (isset($this->data['new'])) foreach ($this->data['new'] as $idx => $column) {
119 $this->data['new'][$idx]['label'] = $this->fixLabel($column['label'], $labels);
140 msg(sprintf($this->helper->getLang('duplicate_label'), $wantedlabel, $fixedlabel), -1);
141 $this->data['cols']['label'] = $fixedlabel;
152 if (!$this->time) $this->time = time();
154 $config = $this->data['config'] ?? '{}';
158 $this->sqlite->query($sql, [$this->table, $this->time, $this->user, $config]);
159 $this->newschemaid = $this->sqlite->queryValue('SELECT last_insert_rowid()');
161 if (!$this->newschemaid) return false;
170 foreach ($this->oldschema->getColumns() as $column) {
176 if (isset($this->data['cols'][$column->getColref()])) {
177 // todo I'm not too happy with this hardcoded here -
179 $newEntry['config'] = $this->data['cols'][$column->getColref()]['config'];
180 $newEntry['label'] = $this->data['cols'][$column->getColref()]['label'];
181 $newEntry['ismulti'] = $this->data['cols'][$column->getColref()]['ismulti'] ?? 0;
182 $newEntry['class'] = $this->data['cols'][$column->getColref()]['class'];
183 $sort = $this->data['cols'][$column->getColref()]['sort'];
184 $enabled = (bool)($this->data['cols'][$column->getColref()]['isenabled'] ?? 0);
188 $ok = $this->sqlite->saveRecord('types', $newEntry);
190 $newTid = $this->sqlite->queryValue('SELECT last_insert_rowid()');
193 $this->migrateSingleToMulti($this->oldschema->getTable(), $column->getColref());
200 // add this type to the schema columns
202 'sid' => $this->newschemaid,
208 $ok = $this->sqlite->saveRecord('schema_cols', $schemaEntry);
224 $valueSet = $this->sqlite->queryAll($sqlSelect);
248 $this->sqlite->query($sqlInsert, $arguments);
258 if (!isset($this->data['new'])) return true;
260 $colref = count($this->oldschema->getColumns()) + 1;
262 foreach ($this->data['new'] as $column) {
265 // todo this duplicates the hardcoding as in the function above
278 if (!$this->addDataTableColumn($colref)) {
283 $ok = $this->sqlite->saveRecord('types', $newEntry);
285 $newTid = $this->sqlite->queryValue('SELECT last_insert_rowid()');
290 // add this type to the schema columns
292 'sid' => $this->newschemaid,
298 $ok = $this->sqlite->saveRecord('schema_cols', $schemaEntry);
317 $tbl = 'data_' . $this->table;
326 $ok = $ok && (bool)$this->sqlite->query($sql);
328 $tbl = 'multi_' . $this->table;
340 $ok = $ok && (bool)$this->sqlite->query($sql);
353 $tbl = 'data_' . $this->table;
355 if (!$this->sqlite->query($sql)) {
367 $this->user = $user;
368 return $this;