You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Version13000Date20170718121200.php 28KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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(['mtime'], 'fs_mtime');
  252. $table->addIndex(['size'], 'fs_size');
  253. }
  254. if (!$schema->hasTable('group_user')) {
  255. $table = $schema->createTable('group_user');
  256. $table->addColumn('gid', 'string', [
  257. 'notnull' => true,
  258. 'length' => 64,
  259. 'default' => '',
  260. ]);
  261. $table->addColumn('uid', 'string', [
  262. 'notnull' => true,
  263. 'length' => 64,
  264. 'default' => '',
  265. ]);
  266. $table->setPrimaryKey(['gid', 'uid']);
  267. $table->addIndex(['uid'], 'gu_uid_index');
  268. }
  269. if (!$schema->hasTable('group_admin')) {
  270. $table = $schema->createTable('group_admin');
  271. $table->addColumn('gid', 'string', [
  272. 'notnull' => true,
  273. 'length' => 64,
  274. 'default' => '',
  275. ]);
  276. $table->addColumn('uid', 'string', [
  277. 'notnull' => true,
  278. 'length' => 64,
  279. 'default' => '',
  280. ]);
  281. $table->setPrimaryKey(['gid', 'uid']);
  282. $table->addIndex(['uid'], 'group_admin_uid');
  283. }
  284. if (!$schema->hasTable('groups')) {
  285. $table = $schema->createTable('groups');
  286. $table->addColumn('gid', 'string', [
  287. 'notnull' => true,
  288. 'length' => 64,
  289. 'default' => '',
  290. ]);
  291. $table->setPrimaryKey(['gid']);
  292. }
  293. if (!$schema->hasTable('preferences')) {
  294. $table = $schema->createTable('preferences');
  295. $table->addColumn('userid', 'string', [
  296. 'notnull' => true,
  297. 'length' => 64,
  298. 'default' => '',
  299. ]);
  300. $table->addColumn('appid', 'string', [
  301. 'notnull' => true,
  302. 'length' => 32,
  303. 'default' => '',
  304. ]);
  305. $table->addColumn('configkey', 'string', [
  306. 'notnull' => true,
  307. 'length' => 64,
  308. 'default' => '',
  309. ]);
  310. $table->addColumn('configvalue', 'text', [
  311. 'notnull' => false,
  312. ]);
  313. $table->setPrimaryKey(['userid', 'appid', 'configkey']);
  314. }
  315. if (!$schema->hasTable('properties')) {
  316. $table = $schema->createTable('properties');
  317. $table->addColumn('id', 'integer', [
  318. 'autoincrement' => true,
  319. 'notnull' => true,
  320. 'length' => 4,
  321. ]);
  322. $table->addColumn('userid', 'string', [
  323. 'notnull' => true,
  324. 'length' => 64,
  325. 'default' => '',
  326. ]);
  327. $table->addColumn('propertypath', 'string', [
  328. 'notnull' => true,
  329. 'length' => 255,
  330. 'default' => '',
  331. ]);
  332. $table->addColumn('propertyname', 'string', [
  333. 'notnull' => true,
  334. 'length' => 255,
  335. 'default' => '',
  336. ]);
  337. $table->addColumn('propertyvalue', 'text', [
  338. 'notnull' => true,
  339. ]);
  340. $table->setPrimaryKey(['id']);
  341. $table->addIndex(['userid'], 'property_index');
  342. $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
  343. } else {
  344. $table = $schema->getTable('properties');
  345. if ($table->hasColumn('propertytype')) {
  346. $table->dropColumn('propertytype');
  347. }
  348. if ($table->hasColumn('fileid')) {
  349. $table->dropColumn('fileid');
  350. }
  351. if (!$table->hasColumn('propertypath')) {
  352. $table->addColumn('propertypath', 'string', [
  353. 'notnull' => true,
  354. 'length' => 255,
  355. ]);
  356. }
  357. if (!$table->hasColumn('userid')) {
  358. $table->addColumn('userid', 'string', [
  359. 'notnull' => false,
  360. 'length' => 64,
  361. 'default' => '',
  362. ]);
  363. }
  364. }
  365. if (!$schema->hasTable('share')) {
  366. $table = $schema->createTable('share');
  367. $table->addColumn('id', 'integer', [
  368. 'autoincrement' => true,
  369. 'notnull' => true,
  370. 'length' => 4,
  371. ]);
  372. $table->addColumn('share_type', 'smallint', [
  373. 'notnull' => true,
  374. 'length' => 1,
  375. 'default' => 0,
  376. ]);
  377. $table->addColumn('share_with', 'string', [
  378. 'notnull' => false,
  379. 'length' => 255,
  380. ]);
  381. $table->addColumn('password', 'string', [
  382. 'notnull' => false,
  383. 'length' => 255,
  384. ]);
  385. $table->addColumn('uid_owner', 'string', [
  386. 'notnull' => true,
  387. 'length' => 64,
  388. 'default' => '',
  389. ]);
  390. $table->addColumn('uid_initiator', 'string', [
  391. 'notnull' => false,
  392. 'length' => 64,
  393. ]);
  394. $table->addColumn('parent', 'integer', [
  395. 'notnull' => false,
  396. 'length' => 4,
  397. ]);
  398. $table->addColumn('item_type', 'string', [
  399. 'notnull' => true,
  400. 'length' => 64,
  401. 'default' => '',
  402. ]);
  403. $table->addColumn('item_source', 'string', [
  404. 'notnull' => false,
  405. 'length' => 255,
  406. ]);
  407. $table->addColumn('item_target', 'string', [
  408. 'notnull' => false,
  409. 'length' => 255,
  410. ]);
  411. $table->addColumn('file_source', 'integer', [
  412. 'notnull' => false,
  413. 'length' => 4,
  414. ]);
  415. $table->addColumn('file_target', 'string', [
  416. 'notnull' => false,
  417. 'length' => 512,
  418. ]);
  419. $table->addColumn('permissions', 'smallint', [
  420. 'notnull' => true,
  421. 'length' => 1,
  422. 'default' => 0,
  423. ]);
  424. $table->addColumn('stime', 'bigint', [
  425. 'notnull' => true,
  426. 'length' => 8,
  427. 'default' => 0,
  428. ]);
  429. $table->addColumn('accepted', 'smallint', [
  430. 'notnull' => true,
  431. 'length' => 1,
  432. 'default' => 0,
  433. ]);
  434. $table->addColumn('expiration', 'datetime', [
  435. 'notnull' => false,
  436. ]);
  437. $table->addColumn('token', 'string', [
  438. 'notnull' => false,
  439. 'length' => 32,
  440. ]);
  441. $table->addColumn('mail_send', 'smallint', [
  442. 'notnull' => true,
  443. 'length' => 1,
  444. 'default' => 0,
  445. ]);
  446. $table->addColumn('share_name', 'string', [
  447. 'notnull' => false,
  448. 'length' => 64,
  449. ]);
  450. $table->setPrimaryKey(['id']);
  451. $table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
  452. $table->addIndex(['file_source'], 'file_source_index');
  453. $table->addIndex(['token'], 'token_index');
  454. $table->addIndex(['share_with'], 'share_with_index');
  455. $table->addIndex(['parent'], 'parent_index');
  456. $table->addIndex(['uid_owner'], 'owner_index');
  457. $table->addIndex(['uid_initiator'], 'initiator_index');
  458. } else {
  459. $table = $schema->getTable('share');
  460. if (!$table->hasColumn('password')) {
  461. $table->addColumn('password', 'string', [
  462. 'notnull' => false,
  463. 'length' => 255,
  464. ]);
  465. }
  466. }
  467. if (!$schema->hasTable('jobs')) {
  468. $table = $schema->createTable('jobs');
  469. $table->addColumn('id', 'integer', [
  470. 'autoincrement' => true,
  471. 'notnull' => true,
  472. 'length' => 4,
  473. 'unsigned' => true,
  474. ]);
  475. $table->addColumn('class', 'string', [
  476. 'notnull' => true,
  477. 'length' => 255,
  478. 'default' => '',
  479. ]);
  480. $table->addColumn('argument', 'string', [
  481. 'notnull' => true,
  482. 'length' => 4000,
  483. 'default' => '',
  484. ]);
  485. $table->addColumn('last_run', 'integer', [
  486. 'notnull' => false,
  487. 'default' => 0,
  488. ]);
  489. $table->addColumn('last_checked', 'integer', [
  490. 'notnull' => false,
  491. 'default' => 0,
  492. ]);
  493. $table->addColumn('reserved_at', 'integer', [
  494. 'notnull' => false,
  495. 'default' => 0,
  496. ]);
  497. $table->addColumn('execution_duration', 'integer', [
  498. 'notnull' => true,
  499. 'default' => 0,
  500. ]);
  501. $table->setPrimaryKey(['id']);
  502. $table->addIndex(['class'], 'job_class_index');
  503. }
  504. if (!$schema->hasTable('users')) {
  505. $table = $schema->createTable('users');
  506. $table->addColumn('uid', 'string', [
  507. 'notnull' => true,
  508. 'length' => 64,
  509. 'default' => '',
  510. ]);
  511. $table->addColumn('displayname', 'string', [
  512. 'notnull' => false,
  513. 'length' => 64,
  514. ]);
  515. $table->addColumn('password', 'string', [
  516. 'notnull' => true,
  517. 'length' => 255,
  518. 'default' => '',
  519. ]);
  520. $table->setPrimaryKey(['uid']);
  521. }
  522. if (!$schema->hasTable('authtoken')) {
  523. $table = $schema->createTable('authtoken');
  524. $table->addColumn('id', 'integer', [
  525. 'autoincrement' => true,
  526. 'notnull' => true,
  527. 'length' => 4,
  528. 'unsigned' => true,
  529. ]);
  530. $table->addColumn('uid', 'string', [
  531. 'notnull' => true,
  532. 'length' => 64,
  533. 'default' => '',
  534. ]);
  535. $table->addColumn('login_name', 'string', [
  536. 'notnull' => true,
  537. 'length' => 64,
  538. 'default' => '',
  539. ]);
  540. $table->addColumn('password', 'text', [
  541. 'notnull' => false,
  542. ]);
  543. $table->addColumn('name', 'text', [
  544. 'notnull' => true,
  545. 'default' => '',
  546. ]);
  547. $table->addColumn('token', 'string', [
  548. 'notnull' => true,
  549. 'length' => 200,
  550. 'default' => '',
  551. ]);
  552. $table->addColumn('type', 'smallint', [
  553. 'notnull' => false,
  554. 'length' => 2,
  555. 'default' => 0,
  556. 'unsigned' => true,
  557. ]);
  558. $table->addColumn('remember', 'smallint', [
  559. 'notnull' => false,
  560. 'length' => 1,
  561. 'default' => 0,
  562. 'unsigned' => true,
  563. ]);
  564. $table->addColumn('last_activity', 'integer', [
  565. 'notnull' => false,
  566. 'length' => 4,
  567. 'default' => 0,
  568. 'unsigned' => true,
  569. ]);
  570. $table->addColumn('last_check', 'integer', [
  571. 'notnull' => false,
  572. 'length' => 4,
  573. 'default' => 0,
  574. 'unsigned' => true,
  575. ]);
  576. $table->addColumn('scope', 'text', [
  577. 'notnull' => false,
  578. ]);
  579. $table->setPrimaryKey(['id']);
  580. $table->addUniqueIndex(['token'], 'authtoken_token_index');
  581. $table->addIndex(['last_activity'], 'authtoken_last_activity_idx');
  582. } else {
  583. $table = $schema->getTable('authtoken');
  584. $table->addColumn('scope', 'text', [
  585. 'notnull' => false,
  586. ]);
  587. }
  588. if (!$schema->hasTable('bruteforce_attempts')) {
  589. $table = $schema->createTable('bruteforce_attempts');
  590. $table->addColumn('id', 'integer', [
  591. 'autoincrement' => true,
  592. 'notnull' => true,
  593. 'length' => 4,
  594. 'unsigned' => true,
  595. ]);
  596. $table->addColumn('action', 'string', [
  597. 'notnull' => true,
  598. 'length' => 64,
  599. 'default' => '',
  600. ]);
  601. $table->addColumn('occurred', 'integer', [
  602. 'notnull' => true,
  603. 'length' => 4,
  604. 'default' => 0,
  605. 'unsigned' => true,
  606. ]);
  607. $table->addColumn('ip', 'string', [
  608. 'notnull' => true,
  609. 'length' => 255,
  610. 'default' => '',
  611. ]);
  612. $table->addColumn('subnet', 'string', [
  613. 'notnull' => true,
  614. 'length' => 255,
  615. 'default' => '',
  616. ]);
  617. $table->addColumn('metadata', 'string', [
  618. 'notnull' => true,
  619. 'length' => 255,
  620. 'default' => '',
  621. ]);
  622. $table->setPrimaryKey(['id']);
  623. $table->addIndex(['ip'], 'bruteforce_attempts_ip');
  624. $table->addIndex(['subnet'], 'bruteforce_attempts_subnet');
  625. }
  626. if (!$schema->hasTable('vcategory')) {
  627. $table = $schema->createTable('vcategory');
  628. $table->addColumn('id', 'integer', [
  629. 'autoincrement' => true,
  630. 'notnull' => true,
  631. 'length' => 4,
  632. 'unsigned' => true,
  633. ]);
  634. $table->addColumn('uid', 'string', [
  635. 'notnull' => true,
  636. 'length' => 64,
  637. 'default' => '',
  638. ]);
  639. $table->addColumn('type', 'string', [
  640. 'notnull' => true,
  641. 'length' => 64,
  642. 'default' => '',
  643. ]);
  644. $table->addColumn('category', 'string', [
  645. 'notnull' => true,
  646. 'length' => 255,
  647. 'default' => '',
  648. ]);
  649. $table->setPrimaryKey(['id']);
  650. $table->addIndex(['uid'], 'uid_index');
  651. $table->addIndex(['type'], 'type_index');
  652. $table->addIndex(['category'], 'category_index');
  653. }
  654. if (!$schema->hasTable('vcategory_to_object')) {
  655. $table = $schema->createTable('vcategory_to_object');
  656. $table->addColumn('objid', 'integer', [
  657. 'notnull' => true,
  658. 'length' => 4,
  659. 'default' => 0,
  660. 'unsigned' => true,
  661. ]);
  662. $table->addColumn('categoryid', 'integer', [
  663. 'notnull' => true,
  664. 'length' => 4,
  665. 'default' => 0,
  666. 'unsigned' => true,
  667. ]);
  668. $table->addColumn('type', 'string', [
  669. 'notnull' => true,
  670. 'length' => 64,
  671. 'default' => '',
  672. ]);
  673. $table->setPrimaryKey(['categoryid', 'objid', 'type']);
  674. $table->addIndex(['objid', 'type'], 'vcategory_objectd_index');
  675. }
  676. if (!$schema->hasTable('systemtag')) {
  677. $table = $schema->createTable('systemtag');
  678. $table->addColumn('id', 'integer', [
  679. 'autoincrement' => true,
  680. 'notnull' => true,
  681. 'length' => 4,
  682. 'unsigned' => true,
  683. ]);
  684. $table->addColumn('name', 'string', [
  685. 'notnull' => true,
  686. 'length' => 64,
  687. 'default' => '',
  688. ]);
  689. $table->addColumn('visibility', 'smallint', [
  690. 'notnull' => true,
  691. 'length' => 1,
  692. 'default' => 1,
  693. ]);
  694. $table->addColumn('editable', 'smallint', [
  695. 'notnull' => true,
  696. 'length' => 1,
  697. 'default' => 1,
  698. ]);
  699. $table->setPrimaryKey(['id']);
  700. $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident');
  701. }
  702. if (!$schema->hasTable('systemtag_object_mapping')) {
  703. $table = $schema->createTable('systemtag_object_mapping');
  704. $table->addColumn('objectid', 'string', [
  705. 'notnull' => true,
  706. 'length' => 64,
  707. 'default' => '',
  708. ]);
  709. $table->addColumn('objecttype', 'string', [
  710. 'notnull' => true,
  711. 'length' => 64,
  712. 'default' => '',
  713. ]);
  714. $table->addColumn('systemtagid', 'integer', [
  715. 'notnull' => true,
  716. 'length' => 4,
  717. 'default' => 0,
  718. 'unsigned' => true,
  719. ]);
  720. $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
  721. // $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
  722. }
  723. if (!$schema->hasTable('systemtag_group')) {
  724. $table = $schema->createTable('systemtag_group');
  725. $table->addColumn('systemtagid', 'integer', [
  726. 'notnull' => true,
  727. 'length' => 4,
  728. 'default' => 0,
  729. 'unsigned' => true,
  730. ]);
  731. $table->addColumn('gid', 'string', [
  732. 'notnull' => true,
  733. ]);
  734. $table->setPrimaryKey(['gid', 'systemtagid']);
  735. }
  736. if (!$schema->hasTable('file_locks')) {
  737. $table = $schema->createTable('file_locks');
  738. $table->addColumn('id', 'integer', [
  739. 'autoincrement' => true,
  740. 'notnull' => true,
  741. 'length' => 4,
  742. 'unsigned' => true,
  743. ]);
  744. $table->addColumn('lock', 'integer', [
  745. 'notnull' => true,
  746. 'length' => 4,
  747. 'default' => 0,
  748. ]);
  749. $table->addColumn('key', 'string', [
  750. 'notnull' => true,
  751. 'length' => 64,
  752. ]);
  753. $table->addColumn('ttl', 'integer', [
  754. 'notnull' => true,
  755. 'length' => 4,
  756. 'default' => -1,
  757. ]);
  758. $table->setPrimaryKey(['id']);
  759. $table->addUniqueIndex(['key'], 'lock_key_index');
  760. $table->addIndex(['ttl'], 'lock_ttl_index');
  761. }
  762. if (!$schema->hasTable('comments')) {
  763. $table = $schema->createTable('comments');
  764. $table->addColumn('id', 'integer', [
  765. 'autoincrement' => true,
  766. 'notnull' => true,
  767. 'length' => 4,
  768. 'unsigned' => true,
  769. ]);
  770. $table->addColumn('parent_id', 'integer', [
  771. 'notnull' => true,
  772. 'length' => 4,
  773. 'default' => 0,
  774. 'unsigned' => true,
  775. ]);
  776. $table->addColumn('topmost_parent_id', 'integer', [
  777. 'notnull' => true,
  778. 'length' => 4,
  779. 'default' => 0,
  780. 'unsigned' => true,
  781. ]);
  782. $table->addColumn('children_count', 'integer', [
  783. 'notnull' => true,
  784. 'length' => 4,
  785. 'default' => 0,
  786. 'unsigned' => true,
  787. ]);
  788. $table->addColumn('actor_type', 'string', [
  789. 'notnull' => true,
  790. 'length' => 64,
  791. 'default' => '',
  792. ]);
  793. $table->addColumn('actor_id', 'string', [
  794. 'notnull' => true,
  795. 'length' => 64,
  796. 'default' => '',
  797. ]);
  798. $table->addColumn('message', 'text', [
  799. 'notnull' => false,
  800. ]);
  801. $table->addColumn('verb', 'string', [
  802. 'notnull' => false,
  803. 'length' => 64,
  804. ]);
  805. $table->addColumn('creation_timestamp', 'datetime', [
  806. 'notnull' => false,
  807. ]);
  808. $table->addColumn('latest_child_timestamp', 'datetime', [
  809. 'notnull' => false,
  810. ]);
  811. $table->addColumn('object_type', 'string', [
  812. 'notnull' => true,
  813. 'length' => 64,
  814. 'default' => '',
  815. ]);
  816. $table->addColumn('object_id', 'string', [
  817. 'notnull' => true,
  818. 'length' => 64,
  819. 'default' => '',
  820. ]);
  821. $table->addColumn('reference_id', 'string', [
  822. 'notnull' => false,
  823. 'length' => 64,
  824. ]);
  825. $table->setPrimaryKey(['id']);
  826. $table->addIndex(['parent_id'], 'comments_parent_id_index');
  827. $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
  828. $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
  829. $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
  830. }
  831. if (!$schema->hasTable('comments_read_markers')) {
  832. $table = $schema->createTable('comments_read_markers');
  833. $table->addColumn('user_id', 'string', [
  834. 'notnull' => true,
  835. 'length' => 64,
  836. 'default' => '',
  837. ]);
  838. $table->addColumn('marker_datetime', 'datetime', [
  839. 'notnull' => false,
  840. ]);
  841. $table->addColumn('object_type', 'string', [
  842. 'notnull' => true,
  843. 'length' => 64,
  844. 'default' => '',
  845. ]);
  846. $table->addColumn('object_id', 'string', [
  847. 'notnull' => true,
  848. 'length' => 64,
  849. 'default' => '',
  850. ]);
  851. $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
  852. $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
  853. // $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
  854. }
  855. // if (!$schema->hasTable('credentials')) {
  856. // $table = $schema->createTable('credentials');
  857. // $table->addColumn('user', 'string', [
  858. // 'notnull' => false,
  859. // 'length' => 64,
  860. // ]);
  861. // $table->addColumn('identifier', 'string', [
  862. // 'notnull' => true,
  863. // 'length' => 64,
  864. // ]);
  865. // $table->addColumn('credentials', 'text', [
  866. // 'notnull' => false,
  867. // ]);
  868. // $table->setPrimaryKey(['user', 'identifier']);
  869. // $table->addIndex(['user'], 'credentials_user');
  870. // }
  871. if (!$schema->hasTable('admin_sections')) {
  872. $table = $schema->createTable('admin_sections');
  873. $table->addColumn('id', 'string', [
  874. 'notnull' => true,
  875. 'length' => 64,
  876. ]);
  877. $table->addColumn('class', 'string', [
  878. 'notnull' => true,
  879. 'length' => 255,
  880. 'default' => '',
  881. ]);
  882. $table->addColumn('priority', 'smallint', [
  883. 'notnull' => true,
  884. 'length' => 1,
  885. 'default' => 0,
  886. ]);
  887. $table->setPrimaryKey(['id']);
  888. $table->addUniqueIndex(['class'], 'admin_sections_class');
  889. }
  890. if (!$schema->hasTable('admin_settings')) {
  891. $table = $schema->createTable('admin_settings');
  892. $table->addColumn('id', 'integer', [
  893. 'autoincrement' => true,
  894. 'notnull' => true,
  895. 'length' => 4,
  896. ]);
  897. $table->addColumn('class', 'string', [
  898. 'notnull' => true,
  899. 'length' => 255,
  900. 'default' => '',
  901. ]);
  902. $table->addColumn('section', 'string', [
  903. 'notnull' => false,
  904. 'length' => 64,
  905. ]);
  906. $table->addColumn('priority', 'smallint', [
  907. 'notnull' => true,
  908. 'length' => 1,
  909. 'default' => 0,
  910. ]);
  911. $table->setPrimaryKey(['id']);
  912. $table->addUniqueIndex(['class'], 'admin_settings_class');
  913. $table->addIndex(['section'], 'admin_settings_section');
  914. }
  915. if (!$schema->hasTable('personal_sections')) {
  916. $table = $schema->createTable('personal_sections');
  917. $table->addColumn('id', 'string', [
  918. 'notnull' => true,
  919. 'length' => 64,
  920. ]);
  921. $table->addColumn('class', 'string', [
  922. 'notnull' => true,
  923. 'length' => 255,
  924. 'default' => '',
  925. ]);
  926. $table->addColumn('priority', 'smallint', [
  927. 'notnull' => true,
  928. 'length' => 1,
  929. 'default' => 0,
  930. ]);
  931. $table->setPrimaryKey(['id']);
  932. $table->addUniqueIndex(['class'], 'personal_sections_class');
  933. }
  934. if (!$schema->hasTable('personal_settings')) {
  935. $table = $schema->createTable('personal_settings');
  936. $table->addColumn('id', 'integer', [
  937. 'autoincrement' => true,
  938. 'notnull' => true,
  939. 'length' => 4,
  940. ]);
  941. $table->addColumn('class', 'string', [
  942. 'notnull' => true,
  943. 'length' => 255,
  944. 'default' => '',
  945. ]);
  946. $table->addColumn('section', 'string', [
  947. 'notnull' => false,
  948. 'length' => 64,
  949. ]);
  950. $table->addColumn('priority', 'smallint', [
  951. 'notnull' => true,
  952. 'length' => 1,
  953. 'default' => 0,
  954. ]);
  955. $table->setPrimaryKey(['id']);
  956. $table->addUniqueIndex(['class'], 'personal_settings_class');
  957. $table->addIndex(['section'], 'personal_settings_section');
  958. }
  959. if (!$schema->hasTable('accounts')) {
  960. $table = $schema->createTable('accounts');
  961. $table->addColumn('uid', 'string', [
  962. 'notnull' => true,
  963. 'length' => 64,
  964. 'default' => '',
  965. ]);
  966. $table->addColumn('data', 'text', [
  967. 'notnull' => true,
  968. 'default' => '',
  969. ]);
  970. $table->setPrimaryKey(['uid']);
  971. }
  972. return $schema;
  973. }
  974. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  975. /** @var ISchemaWrapper $schema */
  976. $schema = $schemaClosure();
  977. if (!$schema->hasTable('dav_properties')) {
  978. return;
  979. }
  980. $query = $this->connection->getQueryBuilder();
  981. $query->select('*')
  982. ->from('dav_properties');
  983. $insert = $this->connection->getQueryBuilder();
  984. $insert->insert('properties')
  985. ->setValue('propertypath', $insert->createParameter('propertypath'))
  986. ->setValue('propertyname', $insert->createParameter('propertyname'))
  987. ->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
  988. ->setValue('userid', $insert->createParameter('userid'));
  989. $result = $query->execute();
  990. while ($row = $result->fetch()) {
  991. preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
  992. $insert->setParameter('propertypath', (string) $row['propertypath'])
  993. ->setParameter('propertyname', (string) $row['propertyname'])
  994. ->setParameter('propertyvalue', (string) $row['propertyvalue'])
  995. ->setParameter('userid', ($match[2] ?? ''));
  996. $insert->execute();
  997. }
  998. }
  999. }