1
0

Version13000Date20170718121200.php 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. * @author Georg Ehrke <oc.list@georgehrke.com>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Julius Härtl <jus@bitgrid.net>
  11. * @author Mario Danic <mario@lovelyhq.com>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Robin Appelman <robin@icewind.nl>
  14. * @author Roeland Jago Douma <roeland@famdouma.nl>
  15. *
  16. * @license GNU AGPL version 3 or any later version
  17. *
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License as
  20. * published by the Free Software Foundation, either version 3 of the
  21. * License, or (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. *
  31. */
  32. namespace OC\Core\Migrations;
  33. use OCP\DB\Types;
  34. use OCP\DB\ISchemaWrapper;
  35. use OCP\IDBConnection;
  36. use OCP\Migration\IOutput;
  37. use OCP\Migration\SimpleMigrationStep;
  38. class Version13000Date20170718121200 extends SimpleMigrationStep {
  39. /** @var IDBConnection */
  40. private $connection;
  41. public function __construct(IDBConnection $connection) {
  42. $this->connection = $connection;
  43. }
  44. public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  45. /** @var ISchemaWrapper $schema */
  46. $schema = $schemaClosure();
  47. if (!$schema->hasTable('properties')) {
  48. return;
  49. }
  50. // in case we have a properties table from oc we drop it since we will only migrate
  51. // the dav_properties values in the postSchemaChange step
  52. $table = $schema->getTable('properties');
  53. if ($table->hasColumn('fileid')) {
  54. $qb = $this->connection->getQueryBuilder();
  55. $qb->delete('properties');
  56. $qb->execute();
  57. }
  58. }
  59. /**
  60. * @param IOutput $output
  61. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  62. * @param array $options
  63. * @return null|ISchemaWrapper
  64. * @since 13.0.0
  65. */
  66. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  67. /** @var ISchemaWrapper $schema */
  68. $schema = $schemaClosure();
  69. if (!$schema->hasTable('appconfig')) {
  70. $table = $schema->createTable('appconfig');
  71. $table->addColumn('appid', 'string', [
  72. 'notnull' => true,
  73. 'length' => 32,
  74. 'default' => '',
  75. ]);
  76. $table->addColumn('configkey', 'string', [
  77. 'notnull' => true,
  78. 'length' => 64,
  79. 'default' => '',
  80. ]);
  81. $table->addColumn('configvalue', 'text', [
  82. 'notnull' => false,
  83. ]);
  84. $table->setPrimaryKey(['appid', 'configkey']);
  85. $table->addIndex(['configkey'], 'appconfig_config_key_index');
  86. $table->addIndex(['appid'], 'appconfig_appid_key');
  87. }
  88. if (!$schema->hasTable('storages')) {
  89. $table = $schema->createTable('storages');
  90. $table->addColumn('id', 'string', [
  91. 'notnull' => false,
  92. 'length' => 64,
  93. ]);
  94. $table->addColumn('numeric_id', Types::BIGINT, [
  95. 'autoincrement' => true,
  96. 'notnull' => true,
  97. 'length' => 20,
  98. ]);
  99. $table->addColumn('available', 'integer', [
  100. 'notnull' => true,
  101. 'default' => 1,
  102. ]);
  103. $table->addColumn('last_checked', 'integer', [
  104. 'notnull' => false,
  105. ]);
  106. $table->setPrimaryKey(['numeric_id']);
  107. $table->addUniqueIndex(['id'], 'storages_id_index');
  108. }
  109. if (!$schema->hasTable('mounts')) {
  110. $table = $schema->createTable('mounts');
  111. $table->addColumn('id', 'integer', [
  112. 'autoincrement' => true,
  113. 'notnull' => true,
  114. 'length' => 4,
  115. ]);
  116. $table->addColumn('storage_id', Types::BIGINT, [
  117. 'notnull' => true,
  118. 'length' => 20,
  119. ]);
  120. $table->addColumn('root_id', Types::BIGINT, [
  121. 'notnull' => true,
  122. 'length' => 20,
  123. ]);
  124. $table->addColumn('user_id', 'string', [
  125. 'notnull' => true,
  126. 'length' => 64,
  127. ]);
  128. $table->addColumn('mount_point', 'string', [
  129. 'notnull' => true,
  130. 'length' => 4000,
  131. ]);
  132. $table->addColumn('mount_id', Types::BIGINT, [
  133. 'notnull' => false,
  134. 'length' => 20,
  135. ]);
  136. $table->setPrimaryKey(['id']);
  137. $table->addIndex(['user_id'], 'mounts_user_index');
  138. $table->addIndex(['storage_id'], 'mounts_storage_index');
  139. $table->addIndex(['root_id'], 'mounts_root_index');
  140. $table->addIndex(['mount_id'], 'mounts_mount_id_index');
  141. $table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index');
  142. } else {
  143. $table = $schema->getTable('mounts');
  144. $table->addColumn('mount_id', Types::BIGINT, [
  145. 'notnull' => false,
  146. 'length' => 20,
  147. ]);
  148. if (!$table->hasIndex('mounts_mount_id_index')) {
  149. $table->addIndex(['mount_id'], 'mounts_mount_id_index');
  150. }
  151. }
  152. if (!$schema->hasTable('mimetypes')) {
  153. $table = $schema->createTable('mimetypes');
  154. $table->addColumn('id', Types::BIGINT, [
  155. 'autoincrement' => true,
  156. 'notnull' => true,
  157. 'length' => 20,
  158. ]);
  159. $table->addColumn('mimetype', 'string', [
  160. 'notnull' => true,
  161. 'length' => 255,
  162. 'default' => '',
  163. ]);
  164. $table->setPrimaryKey(['id']);
  165. $table->addUniqueIndex(['mimetype'], 'mimetype_id_index');
  166. }
  167. if (!$schema->hasTable('filecache')) {
  168. $table = $schema->createTable('filecache');
  169. $table->addColumn('fileid', Types::BIGINT, [
  170. 'autoincrement' => true,
  171. 'notnull' => true,
  172. 'length' => 20,
  173. ]);
  174. $table->addColumn('storage', Types::BIGINT, [
  175. 'notnull' => true,
  176. 'length' => 20,
  177. 'default' => 0,
  178. ]);
  179. $table->addColumn('path', 'string', [
  180. 'notnull' => false,
  181. 'length' => 4000,
  182. ]);
  183. $table->addColumn('path_hash', 'string', [
  184. 'notnull' => true,
  185. 'length' => 32,
  186. 'default' => '',
  187. ]);
  188. $table->addColumn('parent', Types::BIGINT, [
  189. 'notnull' => true,
  190. 'length' => 20,
  191. 'default' => 0,
  192. ]);
  193. $table->addColumn('name', 'string', [
  194. 'notnull' => false,
  195. 'length' => 250,
  196. ]);
  197. $table->addColumn('mimetype', Types::BIGINT, [
  198. 'notnull' => true,
  199. 'length' => 20,
  200. 'default' => 0,
  201. ]);
  202. $table->addColumn('mimepart', Types::BIGINT, [
  203. 'notnull' => true,
  204. 'length' => 20,
  205. 'default' => 0,
  206. ]);
  207. $table->addColumn('size', 'bigint', [
  208. 'notnull' => true,
  209. 'length' => 8,
  210. 'default' => 0,
  211. ]);
  212. $table->addColumn('mtime', Types::BIGINT, [
  213. 'notnull' => true,
  214. 'length' => 20,
  215. 'default' => 0,
  216. ]);
  217. $table->addColumn('storage_mtime', Types::BIGINT, [
  218. 'notnull' => true,
  219. 'length' => 20,
  220. 'default' => 0,
  221. ]);
  222. $table->addColumn('encrypted', 'integer', [
  223. 'notnull' => true,
  224. 'length' => 4,
  225. 'default' => 0,
  226. ]);
  227. $table->addColumn('unencrypted_size', 'bigint', [
  228. 'notnull' => true,
  229. 'length' => 8,
  230. 'default' => 0,
  231. ]);
  232. $table->addColumn('etag', 'string', [
  233. 'notnull' => false,
  234. 'length' => 40,
  235. ]);
  236. $table->addColumn('permissions', 'integer', [
  237. 'notnull' => false,
  238. 'length' => 4,
  239. 'default' => 0,
  240. ]);
  241. $table->addColumn('checksum', 'string', [
  242. 'notnull' => false,
  243. 'length' => 255,
  244. ]);
  245. $table->setPrimaryKey(['fileid']);
  246. $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash');
  247. $table->addIndex(['parent', 'name'], 'fs_parent_name_hash');
  248. $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype');
  249. $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart');
  250. $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size');
  251. $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size');
  252. $table->addIndex(['mtime'], 'fs_mtime');
  253. $table->addIndex(['size'], 'fs_size');
  254. }
  255. if (!$schema->hasTable('group_user')) {
  256. $table = $schema->createTable('group_user');
  257. $table->addColumn('gid', 'string', [
  258. 'notnull' => true,
  259. 'length' => 64,
  260. 'default' => '',
  261. ]);
  262. $table->addColumn('uid', 'string', [
  263. 'notnull' => true,
  264. 'length' => 64,
  265. 'default' => '',
  266. ]);
  267. $table->setPrimaryKey(['gid', 'uid']);
  268. $table->addIndex(['uid'], 'gu_uid_index');
  269. }
  270. if (!$schema->hasTable('group_admin')) {
  271. $table = $schema->createTable('group_admin');
  272. $table->addColumn('gid', 'string', [
  273. 'notnull' => true,
  274. 'length' => 64,
  275. 'default' => '',
  276. ]);
  277. $table->addColumn('uid', 'string', [
  278. 'notnull' => true,
  279. 'length' => 64,
  280. 'default' => '',
  281. ]);
  282. $table->setPrimaryKey(['gid', 'uid']);
  283. $table->addIndex(['uid'], 'group_admin_uid');
  284. }
  285. if (!$schema->hasTable('groups')) {
  286. $table = $schema->createTable('groups');
  287. $table->addColumn('gid', 'string', [
  288. 'notnull' => true,
  289. 'length' => 64,
  290. 'default' => '',
  291. ]);
  292. $table->setPrimaryKey(['gid']);
  293. }
  294. if (!$schema->hasTable('preferences')) {
  295. $table = $schema->createTable('preferences');
  296. $table->addColumn('userid', 'string', [
  297. 'notnull' => true,
  298. 'length' => 64,
  299. 'default' => '',
  300. ]);
  301. $table->addColumn('appid', 'string', [
  302. 'notnull' => true,
  303. 'length' => 32,
  304. 'default' => '',
  305. ]);
  306. $table->addColumn('configkey', 'string', [
  307. 'notnull' => true,
  308. 'length' => 64,
  309. 'default' => '',
  310. ]);
  311. $table->addColumn('configvalue', 'text', [
  312. 'notnull' => false,
  313. ]);
  314. $table->setPrimaryKey(['userid', 'appid', 'configkey']);
  315. }
  316. if (!$schema->hasTable('properties')) {
  317. $table = $schema->createTable('properties');
  318. $table->addColumn('id', 'integer', [
  319. 'autoincrement' => true,
  320. 'notnull' => true,
  321. 'length' => 4,
  322. ]);
  323. $table->addColumn('userid', 'string', [
  324. 'notnull' => true,
  325. 'length' => 64,
  326. 'default' => '',
  327. ]);
  328. $table->addColumn('propertypath', 'string', [
  329. 'notnull' => true,
  330. 'length' => 255,
  331. 'default' => '',
  332. ]);
  333. $table->addColumn('propertyname', 'string', [
  334. 'notnull' => true,
  335. 'length' => 255,
  336. 'default' => '',
  337. ]);
  338. $table->addColumn('propertyvalue', 'text', [
  339. 'notnull' => true,
  340. ]);
  341. $table->setPrimaryKey(['id']);
  342. $table->addIndex(['userid'], 'property_index');
  343. $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
  344. } else {
  345. $table = $schema->getTable('properties');
  346. if ($table->hasColumn('propertytype')) {
  347. $table->dropColumn('propertytype');
  348. }
  349. if ($table->hasColumn('fileid')) {
  350. $table->dropColumn('fileid');
  351. }
  352. if (!$table->hasColumn('propertypath')) {
  353. $table->addColumn('propertypath', 'string', [
  354. 'notnull' => true,
  355. 'length' => 255,
  356. ]);
  357. }
  358. if (!$table->hasColumn('userid')) {
  359. $table->addColumn('userid', 'string', [
  360. 'notnull' => false,
  361. 'length' => 64,
  362. 'default' => '',
  363. ]);
  364. }
  365. }
  366. if (!$schema->hasTable('share')) {
  367. $table = $schema->createTable('share');
  368. $table->addColumn('id', 'integer', [
  369. 'autoincrement' => true,
  370. 'notnull' => true,
  371. 'length' => 4,
  372. ]);
  373. $table->addColumn('share_type', 'smallint', [
  374. 'notnull' => true,
  375. 'length' => 1,
  376. 'default' => 0,
  377. ]);
  378. $table->addColumn('share_with', 'string', [
  379. 'notnull' => false,
  380. 'length' => 255,
  381. ]);
  382. $table->addColumn('password', 'string', [
  383. 'notnull' => false,
  384. 'length' => 255,
  385. ]);
  386. $table->addColumn('uid_owner', 'string', [
  387. 'notnull' => true,
  388. 'length' => 64,
  389. 'default' => '',
  390. ]);
  391. $table->addColumn('uid_initiator', 'string', [
  392. 'notnull' => false,
  393. 'length' => 64,
  394. ]);
  395. $table->addColumn('parent', 'integer', [
  396. 'notnull' => false,
  397. 'length' => 4,
  398. ]);
  399. $table->addColumn('item_type', 'string', [
  400. 'notnull' => true,
  401. 'length' => 64,
  402. 'default' => '',
  403. ]);
  404. $table->addColumn('item_source', 'string', [
  405. 'notnull' => false,
  406. 'length' => 255,
  407. ]);
  408. $table->addColumn('item_target', 'string', [
  409. 'notnull' => false,
  410. 'length' => 255,
  411. ]);
  412. $table->addColumn('file_source', 'integer', [
  413. 'notnull' => false,
  414. 'length' => 4,
  415. ]);
  416. $table->addColumn('file_target', 'string', [
  417. 'notnull' => false,
  418. 'length' => 512,
  419. ]);
  420. $table->addColumn('permissions', 'smallint', [
  421. 'notnull' => true,
  422. 'length' => 1,
  423. 'default' => 0,
  424. ]);
  425. $table->addColumn('stime', 'bigint', [
  426. 'notnull' => true,
  427. 'length' => 8,
  428. 'default' => 0,
  429. ]);
  430. $table->addColumn('accepted', 'smallint', [
  431. 'notnull' => true,
  432. 'length' => 1,
  433. 'default' => 0,
  434. ]);
  435. $table->addColumn('expiration', 'datetime', [
  436. 'notnull' => false,
  437. ]);
  438. $table->addColumn('token', 'string', [
  439. 'notnull' => false,
  440. 'length' => 32,
  441. ]);
  442. $table->addColumn('mail_send', 'smallint', [
  443. 'notnull' => true,
  444. 'length' => 1,
  445. 'default' => 0,
  446. ]);
  447. $table->addColumn('share_name', 'string', [
  448. 'notnull' => false,
  449. 'length' => 64,
  450. ]);
  451. $table->setPrimaryKey(['id']);
  452. $table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
  453. $table->addIndex(['file_source'], 'file_source_index');
  454. $table->addIndex(['token'], 'token_index');
  455. $table->addIndex(['share_with'], 'share_with_index');
  456. $table->addIndex(['parent'], 'parent_index');
  457. $table->addIndex(['uid_owner'], 'owner_index');
  458. $table->addIndex(['uid_initiator'], 'initiator_index');
  459. } else {
  460. $table = $schema->getTable('share');
  461. if (!$table->hasColumn('password')) {
  462. $table->addColumn('password', 'string', [
  463. 'notnull' => false,
  464. 'length' => 255,
  465. ]);
  466. }
  467. }
  468. if (!$schema->hasTable('jobs')) {
  469. $table = $schema->createTable('jobs');
  470. $table->addColumn('id', 'integer', [
  471. 'autoincrement' => true,
  472. 'notnull' => true,
  473. 'length' => 4,
  474. 'unsigned' => true,
  475. ]);
  476. $table->addColumn('class', 'string', [
  477. 'notnull' => true,
  478. 'length' => 255,
  479. 'default' => '',
  480. ]);
  481. $table->addColumn('argument', 'string', [
  482. 'notnull' => true,
  483. 'length' => 4000,
  484. 'default' => '',
  485. ]);
  486. $table->addColumn('last_run', 'integer', [
  487. 'notnull' => false,
  488. 'default' => 0,
  489. ]);
  490. $table->addColumn('last_checked', 'integer', [
  491. 'notnull' => false,
  492. 'default' => 0,
  493. ]);
  494. $table->addColumn('reserved_at', 'integer', [
  495. 'notnull' => false,
  496. 'default' => 0,
  497. ]);
  498. $table->addColumn('execution_duration', 'integer', [
  499. 'notnull' => true,
  500. 'default' => 0,
  501. ]);
  502. $table->setPrimaryKey(['id']);
  503. $table->addIndex(['class'], 'job_class_index');
  504. }
  505. if (!$schema->hasTable('users')) {
  506. $table = $schema->createTable('users');
  507. $table->addColumn('uid', 'string', [
  508. 'notnull' => true,
  509. 'length' => 64,
  510. 'default' => '',
  511. ]);
  512. $table->addColumn('displayname', 'string', [
  513. 'notnull' => false,
  514. 'length' => 64,
  515. ]);
  516. $table->addColumn('password', 'string', [
  517. 'notnull' => true,
  518. 'length' => 255,
  519. 'default' => '',
  520. ]);
  521. $table->setPrimaryKey(['uid']);
  522. }
  523. if (!$schema->hasTable('authtoken')) {
  524. $table = $schema->createTable('authtoken');
  525. $table->addColumn('id', 'integer', [
  526. 'autoincrement' => true,
  527. 'notnull' => true,
  528. 'length' => 4,
  529. 'unsigned' => true,
  530. ]);
  531. $table->addColumn('uid', 'string', [
  532. 'notnull' => true,
  533. 'length' => 64,
  534. 'default' => '',
  535. ]);
  536. $table->addColumn('login_name', 'string', [
  537. 'notnull' => true,
  538. 'length' => 64,
  539. 'default' => '',
  540. ]);
  541. $table->addColumn('password', 'text', [
  542. 'notnull' => false,
  543. ]);
  544. $table->addColumn('name', 'text', [
  545. 'notnull' => true,
  546. 'default' => '',
  547. ]);
  548. $table->addColumn('token', 'string', [
  549. 'notnull' => true,
  550. 'length' => 200,
  551. 'default' => '',
  552. ]);
  553. $table->addColumn('type', 'smallint', [
  554. 'notnull' => false,
  555. 'length' => 2,
  556. 'default' => 0,
  557. 'unsigned' => true,
  558. ]);
  559. $table->addColumn('remember', 'smallint', [
  560. 'notnull' => false,
  561. 'length' => 1,
  562. 'default' => 0,
  563. 'unsigned' => true,
  564. ]);
  565. $table->addColumn('last_activity', 'integer', [
  566. 'notnull' => false,
  567. 'length' => 4,
  568. 'default' => 0,
  569. 'unsigned' => true,
  570. ]);
  571. $table->addColumn('last_check', 'integer', [
  572. 'notnull' => false,
  573. 'length' => 4,
  574. 'default' => 0,
  575. 'unsigned' => true,
  576. ]);
  577. $table->addColumn('scope', 'text', [
  578. 'notnull' => false,
  579. ]);
  580. $table->setPrimaryKey(['id']);
  581. $table->addUniqueIndex(['token'], 'authtoken_token_index');
  582. $table->addIndex(['last_activity'], 'authtoken_last_activity_idx');
  583. } else {
  584. $table = $schema->getTable('authtoken');
  585. $table->addColumn('scope', 'text', [
  586. 'notnull' => false,
  587. ]);
  588. }
  589. if (!$schema->hasTable('bruteforce_attempts')) {
  590. $table = $schema->createTable('bruteforce_attempts');
  591. $table->addColumn('id', 'integer', [
  592. 'autoincrement' => true,
  593. 'notnull' => true,
  594. 'length' => 4,
  595. 'unsigned' => true,
  596. ]);
  597. $table->addColumn('action', 'string', [
  598. 'notnull' => true,
  599. 'length' => 64,
  600. 'default' => '',
  601. ]);
  602. $table->addColumn('occurred', 'integer', [
  603. 'notnull' => true,
  604. 'length' => 4,
  605. 'default' => 0,
  606. 'unsigned' => true,
  607. ]);
  608. $table->addColumn('ip', 'string', [
  609. 'notnull' => true,
  610. 'length' => 255,
  611. 'default' => '',
  612. ]);
  613. $table->addColumn('subnet', 'string', [
  614. 'notnull' => true,
  615. 'length' => 255,
  616. 'default' => '',
  617. ]);
  618. $table->addColumn('metadata', 'string', [
  619. 'notnull' => true,
  620. 'length' => 255,
  621. 'default' => '',
  622. ]);
  623. $table->setPrimaryKey(['id']);
  624. $table->addIndex(['ip'], 'bruteforce_attempts_ip');
  625. $table->addIndex(['subnet'], 'bruteforce_attempts_subnet');
  626. }
  627. if (!$schema->hasTable('vcategory')) {
  628. $table = $schema->createTable('vcategory');
  629. $table->addColumn('id', 'integer', [
  630. 'autoincrement' => true,
  631. 'notnull' => true,
  632. 'length' => 4,
  633. 'unsigned' => true,
  634. ]);
  635. $table->addColumn('uid', 'string', [
  636. 'notnull' => true,
  637. 'length' => 64,
  638. 'default' => '',
  639. ]);
  640. $table->addColumn('type', 'string', [
  641. 'notnull' => true,
  642. 'length' => 64,
  643. 'default' => '',
  644. ]);
  645. $table->addColumn('category', 'string', [
  646. 'notnull' => true,
  647. 'length' => 255,
  648. 'default' => '',
  649. ]);
  650. $table->setPrimaryKey(['id']);
  651. $table->addIndex(['uid'], 'uid_index');
  652. $table->addIndex(['type'], 'type_index');
  653. $table->addIndex(['category'], 'category_index');
  654. }
  655. if (!$schema->hasTable('vcategory_to_object')) {
  656. $table = $schema->createTable('vcategory_to_object');
  657. $table->addColumn('objid', 'integer', [
  658. 'notnull' => true,
  659. 'length' => 4,
  660. 'default' => 0,
  661. 'unsigned' => true,
  662. ]);
  663. $table->addColumn('categoryid', 'integer', [
  664. 'notnull' => true,
  665. 'length' => 4,
  666. 'default' => 0,
  667. 'unsigned' => true,
  668. ]);
  669. $table->addColumn('type', 'string', [
  670. 'notnull' => true,
  671. 'length' => 64,
  672. 'default' => '',
  673. ]);
  674. $table->setPrimaryKey(['categoryid', 'objid', 'type']);
  675. $table->addIndex(['objid', 'type'], 'vcategory_objectd_index');
  676. }
  677. if (!$schema->hasTable('systemtag')) {
  678. $table = $schema->createTable('systemtag');
  679. $table->addColumn('id', 'integer', [
  680. 'autoincrement' => true,
  681. 'notnull' => true,
  682. 'length' => 4,
  683. 'unsigned' => true,
  684. ]);
  685. $table->addColumn('name', 'string', [
  686. 'notnull' => true,
  687. 'length' => 64,
  688. 'default' => '',
  689. ]);
  690. $table->addColumn('visibility', 'smallint', [
  691. 'notnull' => true,
  692. 'length' => 1,
  693. 'default' => 1,
  694. ]);
  695. $table->addColumn('editable', 'smallint', [
  696. 'notnull' => true,
  697. 'length' => 1,
  698. 'default' => 1,
  699. ]);
  700. $table->setPrimaryKey(['id']);
  701. $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident');
  702. }
  703. if (!$schema->hasTable('systemtag_object_mapping')) {
  704. $table = $schema->createTable('systemtag_object_mapping');
  705. $table->addColumn('objectid', 'string', [
  706. 'notnull' => true,
  707. 'length' => 64,
  708. 'default' => '',
  709. ]);
  710. $table->addColumn('objecttype', 'string', [
  711. 'notnull' => true,
  712. 'length' => 64,
  713. 'default' => '',
  714. ]);
  715. $table->addColumn('systemtagid', 'integer', [
  716. 'notnull' => true,
  717. 'length' => 4,
  718. 'default' => 0,
  719. 'unsigned' => true,
  720. ]);
  721. $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
  722. // $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
  723. }
  724. if (!$schema->hasTable('systemtag_group')) {
  725. $table = $schema->createTable('systemtag_group');
  726. $table->addColumn('systemtagid', 'integer', [
  727. 'notnull' => true,
  728. 'length' => 4,
  729. 'default' => 0,
  730. 'unsigned' => true,
  731. ]);
  732. $table->addColumn('gid', 'string', [
  733. 'notnull' => true,
  734. ]);
  735. $table->setPrimaryKey(['gid', 'systemtagid']);
  736. }
  737. if (!$schema->hasTable('file_locks')) {
  738. $table = $schema->createTable('file_locks');
  739. $table->addColumn('id', 'integer', [
  740. 'autoincrement' => true,
  741. 'notnull' => true,
  742. 'length' => 4,
  743. 'unsigned' => true,
  744. ]);
  745. $table->addColumn('lock', 'integer', [
  746. 'notnull' => true,
  747. 'length' => 4,
  748. 'default' => 0,
  749. ]);
  750. $table->addColumn('key', 'string', [
  751. 'notnull' => true,
  752. 'length' => 64,
  753. ]);
  754. $table->addColumn('ttl', 'integer', [
  755. 'notnull' => true,
  756. 'length' => 4,
  757. 'default' => -1,
  758. ]);
  759. $table->setPrimaryKey(['id']);
  760. $table->addUniqueIndex(['key'], 'lock_key_index');
  761. $table->addIndex(['ttl'], 'lock_ttl_index');
  762. }
  763. if (!$schema->hasTable('comments')) {
  764. $table = $schema->createTable('comments');
  765. $table->addColumn('id', 'integer', [
  766. 'autoincrement' => true,
  767. 'notnull' => true,
  768. 'length' => 4,
  769. 'unsigned' => true,
  770. ]);
  771. $table->addColumn('parent_id', 'integer', [
  772. 'notnull' => true,
  773. 'length' => 4,
  774. 'default' => 0,
  775. 'unsigned' => true,
  776. ]);
  777. $table->addColumn('topmost_parent_id', 'integer', [
  778. 'notnull' => true,
  779. 'length' => 4,
  780. 'default' => 0,
  781. 'unsigned' => true,
  782. ]);
  783. $table->addColumn('children_count', 'integer', [
  784. 'notnull' => true,
  785. 'length' => 4,
  786. 'default' => 0,
  787. 'unsigned' => true,
  788. ]);
  789. $table->addColumn('actor_type', 'string', [
  790. 'notnull' => true,
  791. 'length' => 64,
  792. 'default' => '',
  793. ]);
  794. $table->addColumn('actor_id', 'string', [
  795. 'notnull' => true,
  796. 'length' => 64,
  797. 'default' => '',
  798. ]);
  799. $table->addColumn('message', 'text', [
  800. 'notnull' => false,
  801. ]);
  802. $table->addColumn('verb', 'string', [
  803. 'notnull' => false,
  804. 'length' => 64,
  805. ]);
  806. $table->addColumn('creation_timestamp', 'datetime', [
  807. 'notnull' => false,
  808. ]);
  809. $table->addColumn('latest_child_timestamp', 'datetime', [
  810. 'notnull' => false,
  811. ]);
  812. $table->addColumn('object_type', 'string', [
  813. 'notnull' => true,
  814. 'length' => 64,
  815. 'default' => '',
  816. ]);
  817. $table->addColumn('object_id', 'string', [
  818. 'notnull' => true,
  819. 'length' => 64,
  820. 'default' => '',
  821. ]);
  822. $table->addColumn('reference_id', 'string', [
  823. 'notnull' => false,
  824. 'length' => 64,
  825. ]);
  826. $table->setPrimaryKey(['id']);
  827. $table->addIndex(['parent_id'], 'comments_parent_id_index');
  828. $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
  829. $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
  830. $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
  831. }
  832. if (!$schema->hasTable('comments_read_markers')) {
  833. $table = $schema->createTable('comments_read_markers');
  834. $table->addColumn('user_id', 'string', [
  835. 'notnull' => true,
  836. 'length' => 64,
  837. 'default' => '',
  838. ]);
  839. $table->addColumn('marker_datetime', 'datetime', [
  840. 'notnull' => false,
  841. ]);
  842. $table->addColumn('object_type', 'string', [
  843. 'notnull' => true,
  844. 'length' => 64,
  845. 'default' => '',
  846. ]);
  847. $table->addColumn('object_id', 'string', [
  848. 'notnull' => true,
  849. 'length' => 64,
  850. 'default' => '',
  851. ]);
  852. $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
  853. $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
  854. // $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
  855. }
  856. // if (!$schema->hasTable('credentials')) {
  857. // $table = $schema->createTable('credentials');
  858. // $table->addColumn('user', 'string', [
  859. // 'notnull' => false,
  860. // 'length' => 64,
  861. // ]);
  862. // $table->addColumn('identifier', 'string', [
  863. // 'notnull' => true,
  864. // 'length' => 64,
  865. // ]);
  866. // $table->addColumn('credentials', 'text', [
  867. // 'notnull' => false,
  868. // ]);
  869. // $table->setPrimaryKey(['user', 'identifier']);
  870. // $table->addIndex(['user'], 'credentials_user');
  871. // }
  872. if (!$schema->hasTable('admin_sections')) {
  873. $table = $schema->createTable('admin_sections');
  874. $table->addColumn('id', 'string', [
  875. 'notnull' => true,
  876. 'length' => 64,
  877. ]);
  878. $table->addColumn('class', 'string', [
  879. 'notnull' => true,
  880. 'length' => 255,
  881. 'default' => '',
  882. ]);
  883. $table->addColumn('priority', 'smallint', [
  884. 'notnull' => true,
  885. 'length' => 1,
  886. 'default' => 0,
  887. ]);
  888. $table->setPrimaryKey(['id']);
  889. $table->addUniqueIndex(['class'], 'admin_sections_class');
  890. }
  891. if (!$schema->hasTable('admin_settings')) {
  892. $table = $schema->createTable('admin_settings');
  893. $table->addColumn('id', 'integer', [
  894. 'autoincrement' => true,
  895. 'notnull' => true,
  896. 'length' => 4,
  897. ]);
  898. $table->addColumn('class', 'string', [
  899. 'notnull' => true,
  900. 'length' => 255,
  901. 'default' => '',
  902. ]);
  903. $table->addColumn('section', 'string', [
  904. 'notnull' => false,
  905. 'length' => 64,
  906. ]);
  907. $table->addColumn('priority', 'smallint', [
  908. 'notnull' => true,
  909. 'length' => 1,
  910. 'default' => 0,
  911. ]);
  912. $table->setPrimaryKey(['id']);
  913. $table->addUniqueIndex(['class'], 'admin_settings_class');
  914. $table->addIndex(['section'], 'admin_settings_section');
  915. }
  916. if (!$schema->hasTable('personal_sections')) {
  917. $table = $schema->createTable('personal_sections');
  918. $table->addColumn('id', 'string', [
  919. 'notnull' => true,
  920. 'length' => 64,
  921. ]);
  922. $table->addColumn('class', 'string', [
  923. 'notnull' => true,
  924. 'length' => 255,
  925. 'default' => '',
  926. ]);
  927. $table->addColumn('priority', 'smallint', [
  928. 'notnull' => true,
  929. 'length' => 1,
  930. 'default' => 0,
  931. ]);
  932. $table->setPrimaryKey(['id']);
  933. $table->addUniqueIndex(['class'], 'personal_sections_class');
  934. }
  935. if (!$schema->hasTable('personal_settings')) {
  936. $table = $schema->createTable('personal_settings');
  937. $table->addColumn('id', 'integer', [
  938. 'autoincrement' => true,
  939. 'notnull' => true,
  940. 'length' => 4,
  941. ]);
  942. $table->addColumn('class', 'string', [
  943. 'notnull' => true,
  944. 'length' => 255,
  945. 'default' => '',
  946. ]);
  947. $table->addColumn('section', 'string', [
  948. 'notnull' => false,
  949. 'length' => 64,
  950. ]);
  951. $table->addColumn('priority', 'smallint', [
  952. 'notnull' => true,
  953. 'length' => 1,
  954. 'default' => 0,
  955. ]);
  956. $table->setPrimaryKey(['id']);
  957. $table->addUniqueIndex(['class'], 'personal_settings_class');
  958. $table->addIndex(['section'], 'personal_settings_section');
  959. }
  960. if (!$schema->hasTable('accounts')) {
  961. $table = $schema->createTable('accounts');
  962. $table->addColumn('uid', 'string', [
  963. 'notnull' => true,
  964. 'length' => 64,
  965. 'default' => '',
  966. ]);
  967. $table->addColumn('data', 'text', [
  968. 'notnull' => true,
  969. 'default' => '',
  970. ]);
  971. $table->setPrimaryKey(['uid']);
  972. }
  973. return $schema;
  974. }
  975. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  976. /** @var ISchemaWrapper $schema */
  977. $schema = $schemaClosure();
  978. if (!$schema->hasTable('dav_properties')) {
  979. return;
  980. }
  981. $query = $this->connection->getQueryBuilder();
  982. $query->select('*')
  983. ->from('dav_properties');
  984. $insert = $this->connection->getQueryBuilder();
  985. $insert->insert('properties')
  986. ->setValue('propertypath', $insert->createParameter('propertypath'))
  987. ->setValue('propertyname', $insert->createParameter('propertyname'))
  988. ->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
  989. ->setValue('userid', $insert->createParameter('userid'));
  990. $result = $query->execute();
  991. while ($row = $result->fetch()) {
  992. preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
  993. $insert->setParameter('propertypath', (string) $row['propertypath'])
  994. ->setParameter('propertyname', (string) $row['propertyname'])
  995. ->setParameter('propertyvalue', (string) $row['propertyvalue'])
  996. ->setParameter('userid', ($match[2] ?? ''));
  997. $insert->execute();
  998. }
  999. }
  1000. }