Changeset View
Changeset View
Standalone View
Standalone View
src/server/shared/schemaentryelement.php
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | 30 | { | |||
---|---|---|---|---|---|
93 | /** Drop data table column for this element. */ | 93 | /** Drop data table column for this element. */ | ||
94 | public function dropDataColumn(Datastore $db) | 94 | public function dropDataColumn(Datastore $db) | ||
95 | { | 95 | { | ||
96 | if ($db->driver() == 'sqlite') { | 96 | if ($db->driver() == 'sqlite') { | ||
97 | error_log('Sqlite does not support dropping columns.'); | 97 | error_log('Sqlite does not support dropping columns.'); | ||
98 | return; | 98 | return; | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | try { | ||||
101 | if ($this->schemaEntry->isScalar()) { | 102 | if ($this->schemaEntry->isScalar()) { | ||
102 | $stmt = $db->prepare('ALTER TABLE ' . $this->schemaEntry->product()->dataTableName() | 103 | $stmt = $db->prepare('ALTER TABLE ' . $this->schemaEntry->product()->dataTableName() | ||
103 | . ' DROP COLUMN ' . $this->dataColumnName()); | 104 | . ' DROP COLUMN ' . $this->dataColumnName()); | ||
104 | $db->execute($stmt); | 105 | $db->execute($stmt); | ||
105 | } else { | 106 | } else { | ||
106 | $stmt = $db->prepare('ALTER TABLE ' . $this->schemaEntry->dataTableName() | 107 | $stmt = $db->prepare('ALTER TABLE ' . $this->schemaEntry->dataTableName() | ||
107 | . ' DROP COLUMN ' . $this->dataColumnName()); | 108 | . ' DROP COLUMN ' . $this->dataColumnName()); | ||
108 | $db->execute($stmt); | 109 | $db->execute($stmt); | ||
109 | } | 110 | } | ||
111 | } catch (RESTException $e) { | ||||
112 | // don't fail hard on column removal, this can leave the db and our schema description in an inconsistent state | ||||
113 | // or block product deletion entirely | ||||
114 | error_log($e->getMessage()); | ||||
115 | // restart transaction so this doesn't block subsequent queries | ||||
116 | $db->rollBack(); | ||||
117 | $db->beginTransaction(); | ||||
118 | } | ||||
110 | } | 119 | } | ||
111 | 120 | | |||
112 | /** Convert a JSON array into an array of SchemaEntryElement instances. */ | 121 | /** Convert a JSON array into an array of SchemaEntryElement instances. */ | ||
113 | static public function fromJson($jsonArray, SchemaEntry &$entry) | 122 | static public function fromJson($jsonArray, SchemaEntry &$entry) | ||
114 | { | 123 | { | ||
115 | $elems = array(); | 124 | $elems = array(); | ||
116 | foreach ($jsonArray as $jsonObj) { | 125 | foreach ($jsonArray as $jsonObj) { | ||
117 | if (!property_exists($jsonObj, 'name') || !property_exists($jsonObj, 'type')) | 126 | if (!property_exists($jsonObj, 'name') || !property_exists($jsonObj, 'type')) | ||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |