m130524_201442_init.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. <?php
  2. use common\helpers\DbDriverHelper;
  3. use yii\db\Migration;
  4. /**
  5. * migrate database tables execute command:
  6. * windows: /path/to/php /path/to/feehiproject/yii.bat migrate frontendUri //your-frontend-domain.com
  7. * unix-like: /path/to/php /path/to/feehiproject/yii migrate frontendUri //your-frontend-domain.com
  8. *
  9. * Class m130524_201442_init
  10. */
  11. class m130524_201442_init extends Migration
  12. {
  13. public function up()
  14. {
  15. $params = $this->getParams();
  16. $frontendUri = "";
  17. $adminUsernameVal = "";
  18. $adminPasswordVal = "";
  19. isset($params['frontendUri']) && $frontendUri = $params['frontendUri'];
  20. isset($params['adminUsername']) && $adminUsernameVal = $params['adminUsername'];
  21. isset($params['adminPassword']) && $adminPasswordVal = $params['adminPassword'];
  22. while( strpos($frontendUri, 'http://') !== 0 && strpos($frontendUri, 'https://') !== 0 && strpos($frontendUri, '//') !== 0 ){
  23. if( $frontendUri == "" ){
  24. yii::$app->controller->stdout("Input your frontend web url(like //www.xxx.com) :");
  25. }else {
  26. yii::$app->controller->stdout("Must begin with 'http', 'https' or '//' :");
  27. }
  28. $frontendUri = trim(fgets(STDIN));
  29. }
  30. while ($adminUsernameVal === "" || $adminUsernameVal === false){
  31. if( $adminUsernameVal === "" ){
  32. yii::$app->controller->stdout("Input your backend admin username :");
  33. }else{
  34. yii::$app->controller->stdout("only alphabet,number,_ and - permitted (/^[a-zA-Z0-9_\-]+$/) :");
  35. }
  36. $adminUsernameVal = trim(fgets(STDIN));
  37. if(!preg_match("/^[a-zA-Z0-9_\-]+$/", $adminUsernameVal)){
  38. $adminUsernameVal = false;
  39. }
  40. }
  41. while ($adminPasswordVal === ""){
  42. if( $adminPasswordVal === "" ){
  43. yii::$app->controller->stdout("Input your backend admin password :");
  44. }else{
  45. yii::$app->controller->stdout("password cannot be blank :");
  46. }
  47. $adminPasswordVal = trim(fgets(STDIN));
  48. }
  49. $tableOptions = null;
  50. if (DbDriverHelper::isMySQL()) {
  51. // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
  52. $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
  53. }
  54. $rawSQLs = [];
  55. if (DbDriverHelper::isPgSQL()){
  56. $rawSQLs[] = ["ALTER SEQUENCE ###TABLE_NAME###_id_seq RESTART WITH 100;"];
  57. }
  58. //table user
  59. $userId = $this->primaryKey();
  60. $userUsername = $this->string()->notNull()->unique();
  61. $userAuthKey = $this->string(32)->notNull();
  62. $userPasswordHash = $this->string()->notNull();
  63. $userPasswordResetToken = $this->string()->unique();
  64. $userEmail = $this->string()->notNull()->unique();
  65. $userAvatar = $this->string()->defaultValue('');
  66. $userStatus = $this->smallInteger()->notNull()->defaultValue(10);
  67. $userCreatedAt = $this->integer()->notNull();
  68. $userUpdatedAt = $this->integer()->notNull();
  69. if (!DbDriverHelper::isSqlite()) {
  70. $userId->unsigned()->comment("user id(auto increment)");
  71. $userUsername->comment("username");
  72. $userAuthKey->comment("auth key for generate logged in cookie");
  73. $userPasswordHash->comment("crypt password");
  74. $userPasswordResetToken->comment("reset password temp token");
  75. $userEmail->comment("user email");
  76. $userAvatar->comment("avatar url");
  77. $userStatus->comment("user status, (normal:10)");
  78. $userCreatedAt->comment("created at");
  79. $userUpdatedAt->comment("updated at");
  80. }
  81. $this->createTable('{{%user}}', [
  82. 'id' => $userId,
  83. 'username' => $userUsername,
  84. 'auth_key' => $userAuthKey,
  85. 'password_hash' => $userPasswordHash,
  86. 'password_reset_token' => $userPasswordResetToken,
  87. 'email' => $userEmail,
  88. 'avatar' => $userAvatar,
  89. 'status' => $userStatus,
  90. 'created_at' => $userCreatedAt,
  91. 'updated_at' => $userUpdatedAt,
  92. ], $tableOptions);
  93. $this->batchInsert("{{%user}}", ['id','username','auth_key','password_hash','email','status','created_at','updated_at',],
  94. [
  95. /**[
  96. '1',
  97. 'aaa',
  98. 'y-I4ci4glWqom_ZeW6IItOCWFx69FjqQ',
  99. '$2y$13$h2GSh/y8qa1WU.ZRVU3VaOr2/Zfh/VxCUfLmbY4xNeZ1Ql2lbMF36',
  100. 'aaa@feehi.com',
  101. '10',
  102. '1469070407',
  103. '0',
  104. ],
  105. [
  106. '2',
  107. 'bbb',
  108. '9wMhzQEqGW8h1_NFBoCYY3StQ_ZJ8UaM',
  109. '$2y$13$MbDa4j1TujVid9Zk0saOYu7eGk/N52nOJjTYr22dCYRhJ/D9jV29.',
  110. 'bbb@feehi.com',
  111. '10',
  112. '1469070568',
  113. '0',
  114. ],**/
  115. ]
  116. );
  117. foreach ($rawSQLs as $sql){
  118. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%user}}"]);
  119. $this->db->createCommand($sql)->execute();
  120. }
  121. //table admin_user
  122. $adminUserId = $this->primaryKey();
  123. $adminUsername = $this->string()->notNull()->unique();
  124. $adminUserAuthKey = $this->string(32)->notNull();
  125. $adminUserPasswordHash = $this->string()->notNull();
  126. $adminUserPasswordResetToken = $this->string()->unique();
  127. $adminUserEmail = $this->string()->notNull()->unique();
  128. $adminUserAvatar = $this->string()->defaultValue('');
  129. $adminUserStatus = $this->smallInteger()->notNull()->defaultValue(10);
  130. $adminUserCreatedAt = $this->integer()->notNull();
  131. $adminUserUpdatedAt = $this->integer()->notNull();
  132. if (!DbDriverHelper::isSqlite()) {
  133. $adminUserId->unsigned()->comment("admin user id(auto increment)");
  134. $adminUsername->comment("admin username");
  135. $adminUserAuthKey->comment("admin user auth key for generate logged in cookie");
  136. $adminUserPasswordHash->comment("admin user crypt password");
  137. $adminUserPasswordResetToken->comment("admin user reset password temp token");
  138. $adminUserEmail->comment("admin user email");
  139. $adminUserAvatar->comment("admin user avatar url");
  140. $adminUserStatus->comment("admin user status, (normal:10)");
  141. $adminUserCreatedAt->comment("created at");
  142. $adminUserUpdatedAt->comment("updated at");
  143. }
  144. $this->createTable('{{%admin_user}}', [
  145. 'id' => $adminUserId,
  146. 'username' => $adminUsername,
  147. 'auth_key' => $adminUserAuthKey,
  148. 'password_hash' => $adminUserPasswordHash,
  149. 'password_reset_token' => $adminUserPasswordResetToken,
  150. 'email' => $adminUserEmail,
  151. 'avatar' => $adminUserAvatar,
  152. 'status' => $adminUserStatus,
  153. 'created_at' => $adminUserCreatedAt,
  154. 'updated_at' => $adminUserUpdatedAt,
  155. ], $tableOptions);
  156. $this->batchInsert("{{%admin_user}}", ['id','username','auth_key','password_hash','email','avatar','status','created_at','updated_at'],
  157. [
  158. [
  159. "1",
  160. $adminUsernameVal,
  161. "zr9mY7lt23oAhj_ZYjydbLJKcbE3FJ19",
  162. Yii::$app->getSecurity()->generatePasswordHash($adminPasswordVal),
  163. "admin@feehi.com",
  164. "",
  165. "10",
  166. "1468288038",
  167. "1476711945",
  168. ],
  169. /*[
  170. "2",
  171. "fff",
  172. "1JC2paBZhxrLPXNEpGDqW8Bp130x0_g6",
  173. '$2y$13$v.WxC/zKWasDR2fVZsa5u.xoVCh.8VE1QtyqCQNFrZO7DgEvZoZhS',
  174. "fff@feehi.com",
  175. "",
  176. "10",
  177. "1469087451",
  178. "1476711969",
  179. ],**/
  180. ]
  181. );
  182. foreach ($rawSQLs as $sql){
  183. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%admin_user}}"]);
  184. $this->db->createCommand($sql)->execute();
  185. }
  186. //table admin_log
  187. $adminLogId = $this->primaryKey();
  188. $adminLogUserId = $this->integer()->unsigned()->notNull();
  189. $adminLogRoute = $this->string()->defaultValue('')->notNull();
  190. $adminLogDescription = $this->text();
  191. $adminLogCreatedAt = $this->integer()->unsigned()->notNull();
  192. if (!DbDriverHelper::isSqlite()) {
  193. $adminLogId->unsigned()->comment("admin log id(auto increment)");
  194. $adminLogUserId->comment("admin user id");
  195. $adminLogRoute->comment("admin user operate route, like article/create");
  196. $adminLogDescription->comment("admin user operate description");
  197. $adminLogCreatedAt->comment("created at");
  198. }
  199. $this->createTable('{{%admin_log}}', [
  200. 'id' => $adminLogId,
  201. 'user_id' => $adminLogUserId,
  202. 'route' => $adminLogRoute,
  203. 'description' => $adminLogDescription,
  204. 'created_at' => $adminLogCreatedAt
  205. ], $tableOptions);
  206. $this->batchInsert("{{%admin_log}}", ["id", "user_id", "route", "description", "created_at"], [
  207. [
  208. '1',
  209. '1',
  210. '/feehi/index',
  211. 'this is a demo',
  212. '1468293965'
  213. ]
  214. ]);
  215. foreach ($rawSQLs as $sql){
  216. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%admin_log}}"]);
  217. $this->db->createCommand($sql)->execute();
  218. }
  219. //table category
  220. $categoryId = $this->primaryKey();
  221. $categoryParentId = $this->integer()->unsigned()->defaultValue(0)->notNull();
  222. $categoryName = $this->string()->notNull();
  223. $categoryAlias = $this->string()->notNull();
  224. $categorySort = $this->integer()->unsigned()->defaultValue(0)->notNull();
  225. $categoryRemark = $this->string()->defaultValue('')->notNull();
  226. $categoryCreatedAt = $this->integer()->unsigned()->notNull();
  227. $categoryUpdatedAt = $this->integer()->unsigned()->defaultValue(0)->notNull();
  228. if (!DbDriverHelper::isSqlite()) {
  229. $categoryId->unsigned()->comment("category id(auto increment)");
  230. $categoryParentId->comment("category parent id(an exist category id)");
  231. $categoryName->comment("category name");
  232. $categoryAlias->comment("category alias");
  233. $categorySort->comment("category order");
  234. $categoryRemark->comment("category remark info");
  235. $categoryCreatedAt->comment("created at");
  236. $categoryUpdatedAt->comment("updated at");
  237. }
  238. $this->createTable('{{%category}}', [
  239. 'id' => $categoryId,
  240. 'parent_id' => $categoryParentId,
  241. 'name' => $categoryName,
  242. 'alias' => $categoryAlias,
  243. 'sort' => $categorySort,
  244. 'remark' => $categoryRemark,
  245. 'created_at' => $categoryCreatedAt,
  246. 'updated_at' => $categoryUpdatedAt,
  247. ], $tableOptions);
  248. $this->batchInsert("{{%category}}", ['id','parent_id','name','alias','sort','created_at','updated_at','remark'],
  249. [
  250. [
  251. '1',
  252. '0',
  253. 'php',
  254. 'php',
  255. '0',
  256. '1468293958',
  257. '0',
  258. '',
  259. ],
  260. [
  261. '2',
  262. '0',
  263. 'java',
  264. 'java',
  265. '0',
  266. '1468293965',
  267. '0',
  268. '',
  269. ],
  270. [
  271. '3',
  272. '0',
  273. 'javascript',
  274. 'javascript',
  275. '0',
  276. '1468293974',
  277. '0',
  278. '',
  279. ],
  280. ]
  281. );
  282. foreach ($rawSQLs as $sql){
  283. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%category}}"]);
  284. $this->db->createCommand($sql)->execute();
  285. }
  286. //table article
  287. $articleId = $this->primaryKey();
  288. $articleCategoryId = $this->integer()->defaultValue(0)->notNull();
  289. $articleType = $this->integer()->defaultValue(0)->notNull();
  290. $articleTitle = $this->string()->notNull();
  291. $articleSubTitle = $this->string()->defaultValue('')->notNull();
  292. $articleSummary = $this->string()->defaultValue('')->notNull();
  293. $articleThumb = $this->string()->defaultValue('')->notNull();
  294. $articleSeoTitle = $this->string()->defaultValue('')->notNull();
  295. $articleSeoKeywords = $this->string()->defaultValue('')->notNull();
  296. $articleSeoDescription = $this->string()->defaultValue('')->notNull();
  297. $articleStatus = $this->smallInteger()->unsigned()->defaultValue(1)->notNull();
  298. $articleSort = $this->integer()->unsigned()->defaultValue(0)->notNull();
  299. $articleAuthorId = $this->integer()->unsigned()->defaultValue(0)->notNull();
  300. $articleAuthorName = $this->string()->defaultValue('')->notNull();
  301. $articleScanCount = $this->integer()->unsigned()->defaultValue(0)->notNull();
  302. $articleCommentCount = $this->integer()->unsigned()->defaultValue(0)->notNull();
  303. $articleCanComment = $this->smallInteger()->unsigned()->defaultValue(1)->notNull();
  304. $articleVisibility = $this->smallInteger()->unsigned()->defaultValue(1)->notNull();
  305. $articlePassword = $this->string()->defaultValue('')->notNull();
  306. $articleFlagHeadLine = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  307. $articleFlagRecommend = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  308. $articleFlagSlideShow = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  309. $articleFlagSpecialRecommend = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  310. $articleFlagRoll = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  311. $articleFlagBold = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  312. $articleFlagPicture = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  313. $articleCreatedAt = $this->integer()->unsigned()->notNull();
  314. $articleUpdatedAt = $this->integer()->unsigned()->defaultValue(0)->notNull();
  315. if (!DbDriverHelper::isSqlite()) {
  316. $articleId->unsigned()->comment("article id(auto increment)");
  317. $articleCategoryId->unsigned()->comment("article category id");
  318. $articleType->unsigned()->comment("type(0 article, 1 page)");
  319. $articleTitle->comment("article title");
  320. $articleSubTitle->comment("article sub title");
  321. $articleSummary->comment("article summary");
  322. $articleThumb->comment("thumb");
  323. $articleSeoTitle->comment("seo title");
  324. $articleSeoKeywords->comment("seo keywords");
  325. $articleSeoDescription->comment("seo description");
  326. $articleStatus->comment("article status(0 draft,1 published)");
  327. $articleSort->comment("article order");
  328. $articleAuthorId->comment("article published by admin user id");
  329. $articleAuthorName->comment("article published by admin username");
  330. $articleScanCount->comment("article visited count");
  331. $articleCommentCount->comment("article comment count");
  332. $articleCanComment->comment("article can be comment. (0 no, 1 yes)");
  333. $articleVisibility->comment("article visibility(1.public,2.after commented,3.password,4.after logged in)");
  334. $articlePassword->comment("article password(plain text)");
  335. $articleFlagHeadLine->comment("is head line(0 no, 1 yes");
  336. $articleFlagRecommend->comment("is recommend(0 no, 1 yes");
  337. $articleFlagSlideShow->comment("is slide show(0 no, 1 yes");
  338. $articleFlagSpecialRecommend->comment("is special recommend(0 no, 1 yes");
  339. $articleFlagRoll->comment("is roll(0 no, 1 yes");
  340. $articleFlagBold->comment("is bold(0 no, 1 yes");
  341. $articleFlagPicture->comment("is picture(0 no, 1 yes");
  342. $articleCreatedAt->comment("created at");
  343. $articleUpdatedAt->comment("updated at");
  344. }
  345. $this->createTable('{{%article}}', [
  346. 'id' => $articleId,
  347. 'cid' => $articleCategoryId,
  348. 'type' => $articleType,
  349. 'title' => $articleTitle,
  350. 'sub_title' => $articleSubTitle,
  351. 'summary' => $articleSummary,
  352. 'thumb' => $articleThumb,
  353. 'seo_title' => $articleSeoTitle,
  354. 'seo_keywords' => $articleSeoKeywords,
  355. 'seo_description' => $articleSeoDescription,
  356. 'status' => $articleStatus,
  357. 'sort' => $articleSort,
  358. 'author_id' => $articleAuthorId,
  359. 'author_name' => $articleAuthorName,
  360. 'scan_count' => $articleScanCount,
  361. 'comment_count' => $articleCommentCount,
  362. 'can_comment' => $articleCanComment,
  363. 'visibility' => $articleVisibility,
  364. 'password' => $articlePassword,
  365. 'flag_headline' => $articleFlagHeadLine,
  366. 'flag_recommend' => $articleFlagRecommend,
  367. 'flag_slide_show' => $articleFlagSlideShow,
  368. 'flag_special_recommend' => $articleFlagSpecialRecommend,
  369. 'flag_roll' => $articleFlagRoll,
  370. 'flag_bold' => $articleFlagBold,
  371. 'flag_picture' => $articleFlagPicture,
  372. 'created_at' => $articleCreatedAt,
  373. 'updated_at' => $articleUpdatedAt,
  374. ], $tableOptions);
  375. $articles = require(__DIR__.'/article.php');
  376. foreach ($articles['article'] as $item){
  377. $this->insert("{{%article}}", [
  378. 'id' => $item[0],
  379. 'cid' => $item[1],
  380. 'type' => $item[2],
  381. 'title' => $item[3],
  382. 'sub_title' => $item[4],
  383. 'summary' => $item[5],
  384. 'thumb' => $item[6],
  385. 'seo_title' => $item[7],
  386. 'seo_keywords' => $item[8],
  387. 'seo_description' => $item[9],
  388. 'status' => $item[10],
  389. 'sort' => $item[11],
  390. 'author_id' => $item[12],
  391. 'author_name' => $item[13],
  392. 'scan_count' => $item[14],
  393. 'comment_count' => $item[15],
  394. 'can_comment' => $item[16],
  395. 'visibility' => $item[17],
  396. 'flag_headline' => $item[18],
  397. 'flag_recommend' => $item[19],
  398. 'flag_slide_show' => $item[20],
  399. 'flag_special_recommend' => $item[21],
  400. 'flag_roll' => $item[22],
  401. 'flag_bold' => $item[23],
  402. 'flag_picture' => $item[24],
  403. 'created_at' => $item[25],
  404. 'updated_at' => $item[26],
  405. ]);
  406. }
  407. foreach ($rawSQLs as $sql){
  408. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%article}}"]);
  409. $this->db->createCommand($sql)->execute();
  410. }
  411. //table article_content
  412. $articleContentId = $this->primaryKey();
  413. $articleContentArticleId = $this->integer()->unsigned()->defaultValue(0)->notNull();
  414. $articleContentContent = $this->text()->notNull();
  415. if (!DbDriverHelper::isSqlite()) {
  416. $articleContentId->unsigned()->comment("article content id(auto increment)");
  417. $articleContentArticleId->comment("article id");
  418. $articleContentContent->comment("article content");
  419. }
  420. $this->createTable('{{%article_content}}', [
  421. 'id' => $articleContentId,
  422. 'aid' => $articleContentArticleId,
  423. 'content' => $articleContentContent,
  424. ], $tableOptions);
  425. foreach($articles['article_content'] as $item){
  426. $this->insert("{{%article_content}}", ['aid'=>$item[1], 'content'=>$item[2]]);
  427. }
  428. foreach ($rawSQLs as $sql){
  429. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%article_content}}"]);
  430. $this->db->createCommand($sql)->execute();
  431. }
  432. //table article_meta
  433. $articleMetaId = $this->primaryKey();
  434. $articleMetaAid = $this->integer()->unsigned()->notNull();
  435. $articleMetaKey = $this->string()->defaultValue('')->notNull();
  436. $articleMetaValue = $this->text()->notNull();
  437. $articleMetaCratedAt = $this->integer()->unsigned()->notNull();
  438. if (!DbDriverHelper::isSqlite()) {
  439. $articleMetaId->unsigned()->comment("article meta id(auto increment)");
  440. $articleMetaAid->comment("article id");
  441. $articleMetaKey->comment("key");
  442. $articleMetaValue->comment("value");
  443. $articleMetaCratedAt->comment("article meta created at");
  444. }
  445. $this->createTable('{{%article_meta}}', [
  446. 'id' => $articleMetaId,
  447. 'aid' => $articleMetaAid,
  448. 'key' => $articleMetaKey,
  449. 'value' => $articleMetaValue,
  450. 'created_at' => $articleMetaCratedAt,
  451. ], $tableOptions);
  452. $this->createIndex("article_meta_index_aid", "{{%article_meta}}", 'aid');
  453. $this->createIndex("article_meta_index_key", "{{%article_meta}}", 'key');
  454. $this->batchInsert("{{%article_meta}}", ['aid','key','value','created_at'],
  455. [
  456. ['1','tag','AngularJS',1507514051],
  457. ['3','tag','Facebook',1507514051],
  458. ['3','tag','hack',1507514051],
  459. ['3','tag','php',1507514051],
  460. ['5','tag','gc',1507514051],
  461. ['5','tag','垃圾回收',1507514051],
  462. ['5','tag','java',1507514051],
  463. ['6','tag','php7',1507514051],
  464. ['6','tag','php',1507514051],
  465. ['6','tag','wordpress',1507514051],
  466. ['8','tag','spring',1507514051],
  467. ['8','tag','java',1507514051],
  468. ['9','tag','css',1507514051],
  469. ['9','tag','重构',1507514051],
  470. ['10','tag','php',1507514051],
  471. ['10','tag','分页',1507514051],
  472. ['11','tag','php脚本',1507514051],
  473. ['11','tag','下载',1507514051],
  474. ['11','tag','代码下载',1507514051],
  475. ['12','tag','java',1507514051],
  476. ['12','tag','Javascript',1507514051],
  477. ['12','tag','Lisp',1507514051],
  478. ['12','tag','php',1507514051],
  479. ['12','tag','Python',1507514051],
  480. ['12','tag','Ruby',1507514051],
  481. ['12','tag','编程语言',1507514051],
  482. ['12','tag','趣文',1507514051],
  483. ['13','tag','缓存',1507514051],
  484. ['13','tag','浏览器缓存',1507514051],
  485. ['13','tag','http协议',1507514051],
  486. ['14','tag','javascript',1507514051],
  487. ['14','tag','流行',1507514051],
  488. ['15','tag','java',1507514051],
  489. ['16','tag','java',1507514051],
  490. ['16','tag','用户界面',1507514051],
  491. ['17','tag','css',1507514051],
  492. ['17','tag','样式',1507514051],
  493. ['18','tag','java',1507514051],
  494. ['18','tag','入门',1507514051],
  495. ['18','tag','编程书籍',1507514051],
  496. ['19','tag','java',1507514051],
  497. ['19','tag','java8',1507514051],
  498. ['19','tag','垃圾收集',1507514051],
  499. ['20','tag','jvm',1507514051],
  500. ['20','tag','java',1507514051],
  501. ['21','tag','jvm',1507514051],
  502. ['21','tag','java',1507514051],
  503. ['22','tag','java',1507514051],
  504. ['22','tag','java集合',1507514051],
  505. ]
  506. );
  507. foreach ($rawSQLs as $sql){
  508. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%article_meta}}"]);
  509. $this->db->createCommand($sql)->execute();
  510. }
  511. //table comment
  512. $commentId = $this->primaryKey();
  513. $commentArticleId = $this->integer()->unsigned()->defaultValue(0)->notNull();
  514. $commentUserId = $this->integer()->unsigned()->defaultValue(0)->notNull();
  515. $commentAdminUserId = $this->integer()->unsigned()->defaultValue(0)->notNull();
  516. $commentReplyTo = $this->integer()->unsigned()->defaultValue(0)->notNull();
  517. $commentNickname = $this->string()->defaultValue('游客')->notNull();
  518. $commentEmail = $this->string()->defaultValue('')->notNull();
  519. $commentWebsiteUrl = $this->string()->defaultValue('')->notNull();
  520. $commentContent = $this->string()->notNull();
  521. $commentIp = $this->string()->defaultValue('')->notNull();
  522. $commentStatus = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  523. $commentCreatedAt = $this->integer()->unsigned()->notNull();
  524. $commentUpdatedAt = $this->integer()->unsigned()->defaultValue(0)->notNull();
  525. if (!DbDriverHelper::isSqlite()) {
  526. $commentId->unsigned()->comment("comment id(auto increment)");
  527. $commentArticleId->comment("article id");
  528. $commentUserId->comment("user id(0 for guest)");
  529. $commentAdminUserId->comment("admin user id(other user reply 0)");
  530. $commentReplyTo->comment("reply to comment id");
  531. $commentNickname->comment("user nickname");
  532. $commentEmail->comment("email");
  533. $commentWebsiteUrl->comment("user website");
  534. $commentContent->comment("comment content");
  535. $commentIp->comment("user ip");
  536. $commentStatus->comment("comment status(0 to be audit, 1 approved, 2 reject");
  537. $commentCreatedAt->comment("created at");
  538. $commentUpdatedAt->comment("updated at");
  539. }
  540. $this->createTable('{{%comment}}', [
  541. 'id' => $commentId,
  542. 'aid' => $commentArticleId,
  543. 'uid' => $commentUserId,
  544. 'admin_id' => $commentAdminUserId,
  545. 'reply_to' => $commentReplyTo,
  546. 'nickname' => $commentNickname,
  547. 'email' => $commentEmail,
  548. 'website_url' => $commentWebsiteUrl,
  549. 'content' => $commentContent,
  550. 'ip' => $commentIp,
  551. 'status' => $commentStatus,
  552. 'created_at' => $commentCreatedAt,
  553. 'updated_at' => $commentUpdatedAt,
  554. ], $tableOptions);
  555. $this->createIndex("comment_index_aid", "{{%comment}}", "aid");
  556. $this->batchInsert("{{%comment}}", ['id','aid','uid','reply_to','nickname','email','website_url','content','ip','status','created_at','updated_at'],
  557. [
  558. [
  559. "1",
  560. "12",
  561. "0",
  562. "0",
  563. "aaa",
  564. "",
  565. "",
  566. "你好,世界!",
  567. "127.0.0.1",
  568. "1",
  569. "1476066961",
  570. "0",
  571. ],
  572. [
  573. "2",
  574. "22",
  575. "0",
  576. "0",
  577. "aaa",
  578. "",
  579. "",
  580. " :mrgreen: :roll: 哎哟,不错哟~",
  581. "127.0.0.1",
  582. "1",
  583. "1476066990",
  584. "0",
  585. ],
  586. [
  587. "3",
  588. "22",
  589. "0",
  590. "2",
  591. "bbb",
  592. "",
  593. "",
  594. "呵呵哒",
  595. "127.0.0.1",
  596. "1",
  597. "1476067011",
  598. "0",
  599. ],
  600. [
  601. "4",
  602. "12",
  603. "0",
  604. "0",
  605. "ccc",
  606. "",
  607. "",
  608. " :shock: ",
  609. "127.0.0.1",
  610. "1",
  611. "1476067042",
  612. "0",
  613. ],
  614. [
  615. "5",
  616. "12",
  617. "0",
  618. "0",
  619. "aaa",
  620. "",
  621. "",
  622. "嘻嘻嘻",
  623. "127.0.0.1",
  624. "1",
  625. "1476067060",
  626. "0",
  627. ],
  628. [
  629. "6",
  630. "21",
  631. "0",
  632. "0",
  633. "aaa",
  634. "",
  635. "",
  636. "流弊哄哄~~~",
  637. "127.0.0.1",
  638. "1",
  639. "1476067093",
  640. "0",
  641. ],
  642. ]
  643. );
  644. foreach ($rawSQLs as $sql){
  645. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%comment}}"]);
  646. $this->db->createCommand($sql)->execute();
  647. }
  648. //table friendly_link
  649. $friendlyLinkId = $this->primaryKey();
  650. $friendlyLinkName = $this->string()->notNull();
  651. $friendlyLinkImage = $this->string()->defaultValue('')->notNull();
  652. $friendlyLinkURL = $this->string()->defaultValue('')->notNull();
  653. $friendlyLinkTarget = $this->string()->defaultValue('_blank')->notNull();
  654. $friendlyLinkSort = $this->integer()->unsigned()->defaultValue(0)->notNull();
  655. $friendlyLinkStatus = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  656. $friendlyLinkCreatedAt = $this->integer()->unsigned()->notNull();
  657. $friendlyLinkIdUpdatedAt = $this->integer()->unsigned()->defaultValue(0)->notNull();
  658. if (!DbDriverHelper::isSqlite()) {
  659. $friendlyLinkId->unsigned()->comment("friendly link id(auto increment)");
  660. $friendlyLinkName->comment("website name");
  661. $friendlyLinkImage->comment("website icon url");
  662. $friendlyLinkURL->comment("website url");
  663. $friendlyLinkTarget->comment("open method(_blank, _self)");
  664. $friendlyLinkSort->comment("order");
  665. $friendlyLinkStatus->comment("status(0 hide, 1 display");
  666. $friendlyLinkCreatedAt->comment("created at");
  667. $friendlyLinkIdUpdatedAt->comment("updated at");
  668. }
  669. $this->createTable('{{%friendly_link}}', [
  670. 'id' => $friendlyLinkId,
  671. 'name' => $friendlyLinkName,
  672. 'image' => $friendlyLinkImage,
  673. 'url' => $friendlyLinkURL,
  674. 'target' => $friendlyLinkTarget,
  675. 'sort' => $friendlyLinkSort,
  676. 'status' => $friendlyLinkStatus,
  677. 'created_at' => $friendlyLinkCreatedAt,
  678. 'updated_at' => $friendlyLinkIdUpdatedAt,
  679. ], $tableOptions);
  680. $this->batchInsert("{{%friendly_link}}", ['id','name','image','url','target','sort','status','created_at','updated_at'],
  681. [
  682. [
  683. '1',
  684. '飞嗨博客',
  685. '',
  686. 'http://blog.feehi.com',
  687. '_blank',
  688. '0',
  689. '1',
  690. '1468303851',
  691. '0',
  692. ],
  693. [
  694. '2',
  695. '飞嗨网',
  696. '',
  697. 'http://www.feehi.com',
  698. '_blank',
  699. '0',
  700. '1',
  701. '1468303882',
  702. '0',
  703. ],
  704. [
  705. '3',
  706. '36kr',
  707. '',
  708. 'http://www.36kr.com',
  709. '_blank',
  710. '0',
  711. '1',
  712. '1468303902',
  713. '0',
  714. ],
  715. [
  716. '4',
  717. '破晓电影',
  718. '',
  719. 'http://www.poxiao.com',
  720. '_blank',
  721. '0',
  722. '1',
  723. '1468303938',
  724. '0',
  725. ],
  726. [
  727. '5',
  728. '翠竹林主题',
  729. '',
  730. 'http://www.cuizl.com/',
  731. '_blank',
  732. '0',
  733. '1',
  734. '1468303974',
  735. '0',
  736. ],
  737. ]
  738. );
  739. foreach ($rawSQLs as $sql){
  740. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%friendly_link}}"]);
  741. $this->db->createCommand($sql)->execute();
  742. }
  743. //table menu
  744. $menuId = $this->primaryKey();
  745. $menuType = $this->integer()->unsigned()->defaultValue(0)->notNull();
  746. $menuParentId = $this->integer()->unsigned()->defaultValue(0)->notNull();
  747. $menuName = $this->string()->notNull();
  748. $menuURL = $this->string()->notNull();
  749. $menuIcon = $this->string()->defaultValue('')->notNull();
  750. $menuSort = $this->float()->unsigned()->defaultValue(0)->notNull();
  751. $menuTarget = $this->string()->defaultValue('_blank')->notNull();
  752. $menuIsAbsoluteURL = $this->smallInteger()->unsigned()->defaultValue(0)->notNull();
  753. $menuIsDisplay = $this->smallInteger()->unsigned()->defaultValue(1)->notNull();
  754. $menuCreatedAt = $this->integer()->unsigned()->notNull();
  755. $menuUpdatedAt = $this->integer()->unsigned()->defaultValue(0)->notNull();
  756. if (!DbDriverHelper::isSqlite()) {
  757. $menuId->unsigned()->comment("menu id(auto increment)");
  758. $menuType->comment("menu type(0 backend, 1 frontend");
  759. $menuParentId->comment("parent menu id");
  760. $menuName->comment("menu name");
  761. $menuURL->comment("menu url");
  762. $menuIcon->comment("menu icon");
  763. $menuSort->comment("menu order");
  764. $menuTarget->comment("open method(_blank, _self");
  765. $menuIsAbsoluteURL->comment("is absolute url");
  766. $menuIsDisplay->comment("is display(0 no, 1 yes");
  767. $menuCreatedAt->comment("created at");
  768. $menuUpdatedAt->comment("updated at");
  769. }
  770. $this->createTable('{{%menu}}', [
  771. 'id' => $menuId,
  772. 'type' => $menuType,
  773. 'parent_id' => $menuParentId,
  774. 'name' => $menuName,
  775. 'url' => $menuURL,
  776. 'icon' => $menuIcon,
  777. 'sort' => $menuSort,
  778. 'target' => $menuTarget,
  779. 'is_absolute_url' => $menuIsAbsoluteURL,
  780. 'is_display' => $menuIsDisplay,
  781. 'created_at' => $menuCreatedAt,
  782. 'updated_at' => $menuUpdatedAt,
  783. ], $tableOptions);
  784. $this->batchInsert("{{%menu}}", ['id','type','parent_id','name','url','icon','sort','target','is_absolute_url','is_display','created_at','updated_at'
  785. ],
  786. [
  787. ['1','0','0','设置','','fa fa-cogs','0','_blank','0','1','1505570067','1505570067'],
  788. ['2','0','1','网站设置','/setting/website','','1','_blank','0','1','1505570108','1505570108'],
  789. ['3','0','1','SMTP设置','setting/smtp','','2','_blank','0','1','1505570155','1505570283'],
  790. ['4','0','1','自定义设置','setting/custom','','4','_blank','0','1','1505570187','1505570187'],
  791. ['5','0','0','菜单','','fa fa-th-list','2','_blank','0','1','1505570320','1512380045'],
  792. ['6','0','5','前台菜单','frontend-menu/index','','0','_blank','0','1','1505570366','1505570366'],
  793. ['7','0','5','后台菜单','menu/index','','0','_blank','0','1','1505570382','1505570382'],
  794. ['8','0','0','内容','','fa fa-edit','3','_blank','0','1','1505570558','1512380045'],
  795. ['9','0','8','文章','article/index','','0','_blank','0','1','1505570610','1505570610'],
  796. ['10','0','8','分类','category/index','','0','_blank','0','1','1505570638','1505570638'],
  797. ['11','0','8','评论','comment/index','','0','_blank','0','1','1505570661','1505570707'],
  798. ['12','0','8','单页','page/index','','0','_blank','0','1','1505570687','1505570687'],
  799. ['13','0','0','用户','user/index','fa fa-users','4','_blank','0','1','1505570745','1512380045'],
  800. ['14','0','0','权限管理','','fa fa-th-large','5','_blank','0','1','1505570819','1512380045'],
  801. ['15','0','14','权限','rbac/permissions','','0','_blank','0','1','1505570862','1505570862'],
  802. ['16','0','14','角色','rbac/roles','','0','_blank','0','1','1505570882','1505570882'],
  803. ['17','0','14','管理员','admin-user/index','','0','_blank','0','1','1505570902','1505570902'],
  804. ['18','0','0','友情链接','friendly-link/index','fa fa-link','6','_blank','0','1','1505570934','1512380045'],
  805. ['19','0','0','缓存','','fa fa-file','7','_blank','0','1','1505570947','1512380045'],
  806. ['20','0','19','清除前台','clear/frontend','','0','_blank','0','1','1505570974','1505570974'],
  807. ['21','0','19','清除后台','clear/backend','','0','_blank','0','1','1505570994','1505570994'],
  808. ['22','0','0','日志','log/index','fa fa-history','8','_blank','0','1','1505571212','1512380045'],
  809. ['23','1','0','首页','article/index','','0','_self','0','1','1505636890','1505637024'],
  810. ['24','1','0','php','{"0":"article/index","cat":"php"}','','0','_self','0','1','1505636915','1505636937'],
  811. ['25','1','0','java','{"0":"article/index","cat":"java"}','','0','_self','0','1','1505636975','1505636975'],
  812. ['26','1','0','javascript','{"0":"article/index","cat":"javascript"}','','0','_self','0','1','1505637000','1505637000'],
  813. ['27','0','0','运营管理','','fa fa-ils','1','_self','0','1','1505637000','1505637000'],
  814. ['28','0','27','Banner管理','banner/index','','0','_self','0','1','1505637000','1505637000'],
  815. ['29','0','27','广告管理','ad/index','','0','_self','0','1','1505637000','1505637000'],
  816. ]
  817. );
  818. foreach ($rawSQLs as $sql){
  819. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%menu}}"]);
  820. $this->db->createCommand($sql)->execute();
  821. }
  822. //table options
  823. $optionsId = $this->primaryKey();
  824. $optionsType = $this->integer()->unsigned()->defaultValue(0)->notNull();
  825. $optionsName = $this->string()->notNull();
  826. $optionsValue = $this->text()->notNull();
  827. $optionsInputType = $this->smallInteger()->unsigned()->defaultValue(1)->notNull();
  828. $optionsAutoload = $this->smallInteger()->unsigned()->defaultValue(1)->notNull();
  829. $optionTips = $this->string()->defaultValue('')->notNull();
  830. $optionsSort = $this->integer()->unsigned()->defaultValue(0)->notNull();
  831. if (!DbDriverHelper::isSqlite()) {
  832. $optionsId->unsigned()->comment("options id(auto increment)");
  833. $optionsType->comment("type (0 system, 1 custom, 2 banner, 3 advertisement");
  834. $optionsName->comment("identifier");
  835. $optionsValue->comment("value");
  836. $optionsInputType->comment("input box type");
  837. $optionsAutoload->comment("is autoload(0 no, 1 yes");
  838. $optionTips->comment("tips");
  839. $optionsSort->comment("order");
  840. }
  841. $this->createTable('{{%options}}', [
  842. 'id' => $optionsId,
  843. 'type' => $optionsType,
  844. 'name' => $optionsName,
  845. 'value' => $optionsValue,
  846. 'input_type' => $optionsInputType,
  847. 'autoload' => $optionsAutoload,
  848. 'tips' => $optionTips,
  849. 'sort' => $optionsSort,
  850. ], $tableOptions);
  851. $this->batchInsert("{{%options}}", ['type','name','value','input_type','tips','autoload','sort'],
  852. [
  853. [
  854. '0',
  855. 'seo_keywords',
  856. '飞嗨,cms,yii2,php,feehi cms',
  857. '1',
  858. '',
  859. '0',
  860. '0',
  861. ],
  862. [
  863. '0',
  864. 'seo_description',
  865. 'Feehi CMS,最好的cms之一',
  866. '1',
  867. '',
  868. '0',
  869. '0',
  870. ],
  871. [
  872. '0',
  873. 'website_title',
  874. 'Feehi CMS',
  875. '1',
  876. '',
  877. '0',
  878. '0',
  879. ],
  880. [
  881. '0',
  882. 'website_description',
  883. 'Based on most popular php framework yii2',
  884. '1',
  885. '',
  886. '0',
  887. '0',
  888. ],
  889. [
  890. '0',
  891. 'website_email',
  892. 'admin@feehi.com',
  893. '1',
  894. '',
  895. '0',
  896. '0',
  897. ],
  898. [
  899. '0',
  900. 'website_language',
  901. 'zh-CN',
  902. '1',
  903. '',
  904. '0',
  905. '0',
  906. ],
  907. [
  908. '0',
  909. 'website_icp',
  910. '粤ICP备15018643号',
  911. '1',
  912. '',
  913. '0',
  914. '0',
  915. ],
  916. [
  917. '0',
  918. 'website_statics_script',
  919. '',
  920. '1',
  921. '',
  922. '0',
  923. '0',
  924. ],
  925. [
  926. '0',
  927. 'website_status',
  928. '1',
  929. '1',
  930. '',
  931. '0',
  932. '0',
  933. ],
  934. [
  935. '0',
  936. 'website_comment',
  937. '1',
  938. '1',
  939. '',
  940. '0',
  941. '0',
  942. ],
  943. [
  944. '0',
  945. 'website_comment_need_verify',
  946. '0',
  947. '1',
  948. '',
  949. '0',
  950. '0',
  951. ],
  952. [
  953. '0',
  954. 'website_timezone',
  955. 'Asia/Shanghai',
  956. '1',
  957. '',
  958. '0',
  959. '0',
  960. ],
  961. [
  962. '0',
  963. 'website_url',
  964. $frontendUri,
  965. '1',
  966. '',
  967. '0',
  968. '0',
  969. ],
  970. [
  971. '0',
  972. 'smtp_host',
  973. '',
  974. '1',
  975. '',
  976. '0',
  977. '0',
  978. ],
  979. [
  980. '0',
  981. 'smtp_username',
  982. '',
  983. '1',
  984. '',
  985. '0',
  986. '0',
  987. ],
  988. [
  989. '0',
  990. 'smtp_password',
  991. '',
  992. '1',
  993. '',
  994. '0',
  995. '0',
  996. ],
  997. [
  998. '0',
  999. 'smtp_port',
  1000. '',
  1001. '1',
  1002. '',
  1003. '0',
  1004. '0',
  1005. ],
  1006. [
  1007. '0',
  1008. 'smtp_encryption',
  1009. '',
  1010. '1',
  1011. '',
  1012. '0',
  1013. '0',
  1014. ],
  1015. [
  1016. '0',
  1017. 'smtp_nickname',
  1018. '',
  1019. '1',
  1020. '',
  1021. '0',
  1022. '0',
  1023. ],
  1024. [
  1025. '1',
  1026. 'weibo',
  1027. 'http://www.weibo.com/feeppp',
  1028. '1',
  1029. '新浪微博',
  1030. '1',
  1031. '0',
  1032. ],
  1033. [
  1034. '1',
  1035. 'facebook',
  1036. 'http://www.facebook.com/liufee',
  1037. '1',
  1038. 'facebook',
  1039. '1',
  1040. '0',
  1041. ],
  1042. [
  1043. '1',
  1044. 'wechat',
  1045. '飞得更高',
  1046. '1',
  1047. '微信',
  1048. '1',
  1049. '0',
  1050. ],
  1051. [
  1052. '1',
  1053. 'qq',
  1054. '1838889850',
  1055. '1',
  1056. 'QQ号码',
  1057. '1',
  1058. '0',
  1059. ],
  1060. [
  1061. '1',
  1062. 'email',
  1063. 'admin@feehi.com',
  1064. '1',
  1065. '邮箱',
  1066. '1',
  1067. '0',
  1068. ],
  1069. ['2', 'index', '[{"sign":"5a251a3013586","img":"\/uploads\/setting\/banner\/5a251a301280d_1.png","target":"_blank","link":"\/view\/11","sort":"3","status":"1","desc":""},{"sign":"5a251a4932a52","img":"\/uploads\/setting\/banner\/5a251a4930fc2_2.jpg","target":"_blank","link":"\/view\/15","sort":"2","status":"1","desc":""},{"sign":"5a251a5690fe9","img":"\/uploads\/setting\/banner\/5a251a568f966_3.jpg","target":"_blank","link":"\/view\/16","sort":"1","status":"1","desc":""}]', '1', '首页banner', '1', '0'],
  1070. ['3', 'sidebar_right_1', '{"ad":"\/uploads\/setting\/ad\/5a292c0fda836_cms.jpg","link":"http://www.feehi.com","target":"_blank","desc":"FeehiCMS","created_at":1512641320,"updated_at":1512647776}', '1', '网站右侧广告位1', '1', '0'],
  1071. ['3', 'sidebar_right_2', '{"ad":"\/uploads\/setting\/ad\/5a291f9236479_22.jpg","link":"","target":"_blank","desc":"\u6700\u597d\u7684\u8fd0\u52a8\u624b\u8868","created_at":1512644498,"updated_at":1512647586}', '1', '网站右侧广告位2', '1', '0'],
  1072. ]
  1073. );
  1074. foreach ($rawSQLs as $sql){
  1075. $sql = SQLHelper::getRealSQL($sql, ['table'=>"{{%options}}"]);
  1076. $this->db->createCommand($sql)->execute();
  1077. }
  1078. }
  1079. public function down()
  1080. {
  1081. $this->dropForeignKey('fk_aid', '{{%article_content}}');
  1082. $this->dropForeignKey('fk_article_meta_aid', '{{%article_meta}}');
  1083. $this->dropForeignKey('fk_comment_aid', '{{%comment}}');
  1084. $this->dropIndex('index_key', '{{%article_meta}}');
  1085. $this->dropIndex('index_aid', '{{%article_meta}}');
  1086. $this->dropIndex('index_aid', '{{%comment}}');
  1087. $this->dropTable('{{%options}}');
  1088. $this->dropTable('{{%menu}}');
  1089. $this->dropTable('{{%friendly_link}}');
  1090. $this->dropTable('{{%comment}}');
  1091. $this->dropTable('{{%article_meta}}');
  1092. $this->dropTable('{{%article_content}}');
  1093. $this->dropIndex('index_title', '{{%article}}');
  1094. $this->dropTable('{{%article}}');
  1095. $this->dropTable('{{%category}}');
  1096. $this->dropTable('{{%admin_log}}');
  1097. $this->dropTable('{{%admin_user}}');
  1098. $this->dropTable('{{%user}}');
  1099. }
  1100. public function getParams()
  1101. {
  1102. $rawParams = [];
  1103. if (isset($_SERVER['argv'])) {
  1104. $rawParams = $_SERVER['argv'];
  1105. array_shift($rawParams);
  1106. }
  1107. $params = [];
  1108. foreach ($rawParams as $param) {
  1109. if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
  1110. $name = $matches[1];
  1111. $params[$name] = isset($matches[3]) ? $matches[3] : true;
  1112. } else {
  1113. $params[] = $param;
  1114. }
  1115. }
  1116. $return = [];
  1117. foreach ($params as $v){
  1118. if( strpos($v, '=') !== false ) {
  1119. $array = explode('=', $v);
  1120. $return[$array[0]] = $array[1];
  1121. }else{
  1122. $return[$v] = "";
  1123. }
  1124. }
  1125. return $return;
  1126. }
  1127. }