1
0

Version13000Date20170718121200.php 28 KB

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