seo,域名绑定,应用映射,帖子链接,html

This commit is contained in:
tao 2022-04-19 17:26:10 +08:00
parent 97f2b926ac
commit 36bdf774ba
102 changed files with 13723 additions and 251 deletions

View File

@ -3,8 +3,8 @@
> TaoLer是一个简单迅捷的轻论坛系统适用于个人或组织区域型信息交流发布平台。
* 官网https://www.aieok.com
* 版本TaoLer 1.9.1
* 日期2022.4.16
* 版本TaoLer 1.9.2
* 日期2022.4.19
webman版新架构已适配90%

View File

@ -10,8 +10,6 @@ use think\facade\Config;
use app\admin\model\Addons as AddonsModel;
use taoler\com\Files;
use taoler\com\Api;
use app\common\lib\SetConf;
use think\App;
use app\common\lib\Zip;
class Addons extends AdminController

View File

@ -2,7 +2,7 @@
/*
* @Author: TaoLer <alipey_tao@qq.com>
* @Date: 2022-04-13 09:54:31
* @LastEditTime: 2022-04-17 16:55:13
* @LastEditTime: 2022-04-19 16:42:47
* @LastEditors: TaoLer
* @Description: 搜索引擎SEO优化设置
* @FilePath: \TaoLer\app\admin\controller\Seo.php
@ -15,7 +15,7 @@ use app\common\controller\AdminController;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use app\common\lib\SetArr;
use taoser\SetArr;
class Seo extends AdminController
{
@ -34,9 +34,16 @@ class Seo extends AdminController
public function push()
{
$data = Request::only(['start_id','end_id']);
if(empty(config('taoler.baidu.push_api'))) return json(['code'=>-1,'msg'=>'请先配置接口push_api']);
$urls = [];
$artAllId = Db::name('article')->where(['delete_time'=>0,'status'=>1])->column('id');
if(empty($data['start_id']) || empty($data['end_id'])) {
$artAllId = Db::name('article')->where(['delete_time'=>0,'status'=>1])->column('id');
} else {
$artAllId = Db::name('article')->where(['delete_time'=>0,'status'=>1])->where('id','between',[$data['start_id'],$data['end_id']])->column('id');
}
foreach($artAllId as $aid) {
$urls[] = $this->getRouteUrl($aid);
}
@ -62,9 +69,13 @@ class Seo extends AdminController
return json(['code'=>0,'msg'=>'成功推送'.$data->success.'条,今天剩余'.$data->remain]);
}
/**
* 百度接口配置
*
* @return void
*/
public function config()
{
//
$baidu = [];
$data = Request::only(['client_id','client_secret','push_api']);
foreach($data as $k => $v) {
@ -76,7 +87,7 @@ class Seo extends AdminController
}
}
}
$res = (new SetArr('taoler'))::edit([
$res = SetArr::name('taoler')->edit([
'baidu' => $baidu,
]);
if($res == true){
@ -150,6 +161,7 @@ class Seo extends AdminController
$str .= <<<STR
<url>
<loc>$url</loc>
<mobile:mobile type="pc,mobile"/>
<lastmod>$time</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
@ -188,7 +200,7 @@ class Seo extends AdminController
}
while($last_id < (int) $maxId);
// 写配置标记最后写入ID
$res = (new SetArr('taoler'))::edit([
$res = SetArr::name('taoler')->edit([
'sitemap' => [
'map_num' => $data['map_num'],
'write_id' => $last_id,
@ -255,13 +267,36 @@ class Seo extends AdminController
{
$indexUrl = $this->getIndexUrl();
$artUrl = (string) url('detail_id', ['id' => $aid]);
if(empty(config('app.domain_bind'))) {
// 未绑定域名
$url = $indexUrl . str_replace('admin','index',$artUrl);
} else {
// 单独绑定域名
$url = $indexUrl . $artUrl;
// 判断是否开启绑定
//$domain_bind = array_key_exists('domain_bind',config('app'));
// 判断index应用是否绑定域名
$bind_index = array_search('index',config('app.domain_bind'));
// 判断admin应用是否绑定域名
$bind_admin = array_search('admin',config('app.domain_bind'));
// 判断index应用是否域名映射
$map_index = array_search('index',config('app.app_map'));
// 判断admin应用是否域名映射
$map_admin = array_search('admin',config('app.app_map'));
$index = $map_index ? $map_index : 'index'; // index应用名
$admin = $map_admin ? $map_admin : 'admin'; // admin应用名
if($bind_index) {
// index绑定域名
$url = $indexUrl . str_replace($admin.'/','',$artUrl);
} else { // index未绑定域名
// admin绑定域名
if($bind_admin) {
$url = $indexUrl .'/' . $index . $artUrl;
} else {
$url = $indexUrl . str_replace($admin,$index,$artUrl);
}
}
return $url;
}

View File

@ -1,4 +1,13 @@
<?php
/*
* @Author: TaoLer <alipey_tao@qq.com>
* @Date: 2021-12-06 16:04:50
* @LastEditTime: 2022-04-19 14:06:54
* @LastEditors: TaoLer
* @Description: 搜索引擎SEO优化设置
* @FilePath: \TaoLer\app\admin\controller\Set.php
* Copyright (c) 2020~2022 http://www.aieok.com All rights reserved.
*/
namespace app\admin\controller;
use app\common\controller\AdminController;
@ -10,10 +19,9 @@ use think\facade\Config;
use app\admin\model\System;
use app\admin\model\MailServer;
use taoler\com\Files;
use app\common\lib\SetConf;
use app\common\lib\SetArr;
use think\facade\Session;
use think\facade\Cookie;
use taoser\SetArr;
class Set extends AdminController
{
@ -35,7 +43,6 @@ class Set extends AdminController
'index' => isset($data['index']) ? $data['index'] : '',
'admin' => isset($data['admin']) ? $data['admin'] : '',
];
} else {
$domain_bind = [
'index' => '',
@ -73,12 +80,12 @@ class Set extends AdminController
$data = array_flip($data);
if(empty(config('app.domain_bind'))){
// 写入token
$res = (new SetArr('app'))::add([
$res = SetArr::name('app')->add([
'domain_bind'=> $data,
]);
}else{
// 编辑
$res = (new SetArr('app'))::edit([
$res = SetArr::name('app')->edit([
'domain_bind'=> $data,
]);
}
@ -86,7 +93,7 @@ class Set extends AdminController
Cookie::delete('adminAuth');
Session::clear();
} else {
$res = (new SetArr('app'))::delete([
$res = SetArr::name('app')->delete([
'domain_bind'=> config('app.domain_bind'),
]);
}
@ -178,15 +185,41 @@ class Set extends AdminController
}
}
$setConf = new SetConf;
$value = [
'config'=>$conf
];
$upRes = $setConf->setConfig('taoler',$value);
return $upRes;
$result = SetArr::name('taoler')->edit($value);
if($result){
$res = ['code'=>0,'msg'=>'配置成功'];
} else {
$res = ['code'=>-1,'msg'=>'配置出错!'];
}
return json($res);
}
}
public function setUrl()
{
//
$data = Request::only(['article_as','cate_as']);
$arr = [
'url_rewrite'=>$data,
];
if(!array_key_exists('url_rewrite',config('taoler'))){
$result = SetArr::name('taoler')->add($arr);
} else {
$result = SetArr::name('taoler')->edit($arr);
}
if($result){
$res = ['code'=>0,'msg'=>'配置成功'];
} else {
$res = ['code'=>-1,'msg'=>'配置出错!'];
}
return json($res);
}
//上传logo
public function upload()
{

View File

@ -23,11 +23,9 @@ use taoler\com\Str;
use taoler\com\Files;
use think\facade\Config;
use think\facade\Log;
use app\common\lib\ZipFile;
use app\common\lib\SetConf;
use app\common\lib\SetArr;
use app\common\lib\SqlFile;
use app\common\lib\Zip;
use taoser\SetArr;
class Upgrade extends AdminController
{
@ -218,16 +216,15 @@ class Upgrade extends AdminController
//更新版本
//Db::name('system')->update(['sys_version_num'=>$version_num,'id'=>1]);
$setConf = new SetConf;
$value = [
'version' => $version_num
];
$upRes = $setConf->setConfig('taoler',$value);
$result = $upRes->getData();
if($result['code'] == -1){
return json(['code'=>-1,'msg'=>'代码写入成功,但'.$result['msg']]);
$res = SetArr::name('taoler')->edit($value);
if($res == false){
return json(['code'=>-1,'msg'=>'代码更新成功,但版本写入失败']);
}
return json(['code'=>0,'msg'=>'升级成功']);
}
@ -363,16 +360,15 @@ class Upgrade extends AdminController
//更新版本
//Db::name('system')->update(['sys_version_num'=>$version_num,'id'=>1]);
$setConf = new SetConf;
$value = [
'version' => $version_num
];
$res = SetArr::name('taoler')->edit($value);
if($res == false){
return json(['code'=>-1,'msg'=>'代码更新成功,但版本写入失败']);
}
$upRes = $setConf->setConfig('taoler',$value);
$result = $upRes->getData();
if($result['code'] == -1){
return json(['code'=>-1,'msg'=>$result['msg']]);
}
return json(['code'=>0,'msg'=>'升级成功']);
}

View File

@ -1,16 +1,18 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
/*
* @Author: TaoLer <alipey_tao@qq.com>
* @Date: 2021-12-06 16:04:50
* @LastEditTime: 2022-04-19 14:31:41
* @LastEditors: TaoLer
* @Description: 搜索引擎SEO优化设置
* @FilePath: \TaoLer\app\admin\route\route.php
* Copyright (c) 2020~2022 http://www.aieok.com All rights reserved.
*/
use think\facade\Route;
//Route::get('jie/:id','index/article/detail');
//详情页URL别称
$detail_as = config('taoler.url_rewrite.article_as');
Route::get('captcha/[:config]','\\think\\captcha\\CaptchaController@index');
//Route::get('jie/:id', '\app\index\controller\Article@detail')->name('detail_id');
Route::get('jie/:id', 'index/Article/detail')->name('detail_id');
Route::get($detail_as.'/:id', '\app\index\controller\Article::detail')->name('detail_id');

View File

@ -70,7 +70,6 @@
,method: 'get'
,exts: 'zip|rar|7z'
,done: function(res){
//console.log(res)
$(this.item).prev("div").children("input").val(res.src)
if(res.code == 0){

View File

@ -94,7 +94,7 @@
//提交 Ajax 成功后,静态更新表格中的数据
$.ajax({
type:"post",
url:"{:url('admin/Addons/add')}",
url:"{:url('Addons/add')}",
data:field,
daType:"json",
success:function (data){

View File

@ -50,17 +50,17 @@
{{# if(d.id == '1'){ }}
<input type="checkbox" name="check" lay-skin="switch" disabled lay-text="通过|禁用" value="1" checked id="{{d.id}}">
{{# } else { }}
{if condition="checkRuleButton('admin/admin/check')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="admincheck" lay-text="通过|禁用" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >{else}<button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-disabled">无权限</button>{/if}
{if condition="checkRuleButton('admin/check')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="admincheck" lay-text="通过|禁用" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >{else}<button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-disabled">无权限</button>{/if}
{{# } }}
</script>
<script type="text/html" id="table-useradmin-admin">
{if condition="checkRuleButton('admin/admin/edit')"}
{if condition="checkRuleButton('admin/edit')"}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
{else /}<a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-edit"></i>编辑</a>{/if}
{{# if(d.id == '1'){ }}
<a class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>
{{# } else { }}
{if condition="checkRuleButton('admin/admin/delete')"}
{if condition="checkRuleButton('admin/delete')"}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
{else /}<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i>删除</a>{/if}
{{# } }}
@ -101,7 +101,7 @@
var field = data.field;
$.ajax({
type:"post",
url:"{:url('admin/admin/index')}",
url:"{:url('admin/index')}",
data:{"id":field.id,"username":field.username,"mobile":field.mobile,"email":field.email},
daType:"json",
success:function (data){
@ -135,7 +135,7 @@
//执行管理员审核
$.ajax({
type:'post',
url:"{:url('admin/admin/check')}",
url:"{:url('admin/check')}",
data:{"id":data.id,"status":data.value,},
dataType:'json',
success:function(res){
@ -208,7 +208,7 @@
//提交 Ajax 成功后,静态更新表格中的数据
$.ajax({
type:"post",
url:"{:url('admin/admin/add')}",
url:"{:url('admin/add')}",
data:{"username":field.username,"password":field.password,"mobile":field.mobile,"email":field.email,"auth_group_id":field.auth_group_id,"status":field.status},
daType:"json",
success:function (data){

View File

@ -1,4 +1,3 @@
{extend name="public:base" /}
{block name="body"}

View File

@ -27,13 +27,13 @@
<table id="LAY-user-back-group" lay-filter="LAY-user-back-group"></table>
<script type="text/html" id="buttonCheck">
{if condition="checkRuleButton('admin/AuthAccess/check')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="groupcheck" lay-text="开启|禁用" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >{else /}<button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-disabled">无权限</button>{/if}
{if condition="checkRuleButton('AuthAccess/check')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="groupcheck" lay-text="开启|禁用" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >{else /}<button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-disabled">无权限</button>{/if}
</script>
<script type="text/html" id="table-useradmin-admin">
{if condition="checkRuleButton('admin/AuthAccess/edit')"}
{if condition="checkRuleButton('AuthAccess/edit')"}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
{else /}<a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-edit"></i>编辑</a>{/if}
{if condition="checkRuleButton('admin/AuthAccess/delete')"}
{if condition="checkRuleButton('AuthAccess/delete')"}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
{else /}<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i>删除</a>{/if}
</script>
@ -72,7 +72,7 @@
form.on('select(LAY-admin-group-type)', function(data){
$.ajax({
type:"post",
url:"{:url('admin/AuthAccess/index')}",
url:"{:url('AuthAccess/index')}",
data:{"uid":data.value},
daType:"json",
success:function (data){

View File

@ -27,14 +27,14 @@
<table id="LAY-user-back-role" lay-filter="LAY-user-back-role"></table>
<script type="text/html" id="buttonCheck">
{if condition="checkRuleButton('admin/AuthGroup/check')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="rolecheck" lay-text="打开|关闭" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >
{if condition="checkRuleButton('AuthGroup/check')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="rolecheck" lay-text="打开|关闭" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >
{else /}<button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-disabled">无权限</button>{/if}
</script>
<script type="text/html" id="table-useradmin-admin">
{if condition="checkRuleButton('admin/AuthGroup/roleedit')"}
{if condition="checkRuleButton('AuthGroup/roleedit')"}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
{else /} <a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-edit"></i>编辑</a>{/if}
{if condition="checkRuleButton('admin/AuthGroup/roledel')"}
{if condition="checkRuleButton('AuthGroup/roledel')"}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
{else /} <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i>删除</a>{/if}
</script>
@ -74,7 +74,7 @@
$.ajax({
type:"post",
url:"{:url('admin/AuthGroup/list')}",
url:"{:url('AuthGroup/list')}",
data:{"id":data.value},
daType:"json",
success:function (data){
@ -111,7 +111,7 @@
//执行角色审核
$.ajax({
type:'post',
url:"{:url('admin/AuthGroup/check')}",
url:"{:url('AuthGroup/check')}",
data:{id:data.id,status:data.value,},
dataType:'json',
success:function(res){
@ -192,7 +192,7 @@
//提交 Ajax 成功后,静态更新表格中的数据
$.ajax({
type:"post",
url:"{:url('admin/AuthGroup/roleAdd')}",
url:"{:url('AuthGroup/roleAdd')}",
data:{"rules":rules,"title":field.title,"descr":field.descr},
daType:"json",
success:function (data){

View File

@ -1,4 +1,3 @@
{extend name="public:base" /}
{block name="body"}
@ -113,9 +112,6 @@
}
});
})
</script>

View File

@ -19,7 +19,7 @@
<!--a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a-->
{{# if(d.id == '1' | d.id == '2' | d.id == '9' | d.id == '10' ){ }}<a class="layui-btn layui-btn-disabled layui-btn-xs">删除</a>
{{# } else { }}
{if condition="checkRuleButton('admin/authrule/delete')"}<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
{if condition="checkRuleButton('authrule/delete')"}<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
{else /}<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled">删除</a>{/if}
{{# } }}
</script>

View File

@ -51,7 +51,7 @@
{
//var index = layer.load();
$.ajax({
url: "{:url('admin/Databackup/backup')}",
url: "{:url('Databackup/backup')}",
type: 'POST', //POST
async: true, //或false,是否异步
dataType: 'json',
@ -85,7 +85,7 @@
//总帐信息
table.render({
elem: '#LAY-app-content-ledger'
,url: "{:url('admin/Database/index')}" //进列表接口
,url: "{:url('Database/index')}" //进列表接口
,toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
,defaultToolbar: ['filter', 'exports', 'print']
,cols: [[

View File

@ -50,7 +50,7 @@
{
var index = layer.load();
$.ajax({
url: "{:url('admin/Database/backup')}",
url: "{:url('Database/backup')}",
type: 'POST', //POST
async: true, //或false,是否异步
dataType: 'json',
@ -85,7 +85,7 @@
//信息
table.render({
elem: '#LAY-app-content-database'
,url: "{:url('admin/Database/index')}" //进列表接口
,url: "{:url('Database/index')}" //进列表接口
,toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
,cols: [[
{type: 'checkbox', fixed: 'left'}

View File

@ -78,12 +78,12 @@
{{# } }}
</script>
<script type="text/html" id="buttonCheck">
{if condition="checkRuleButton('admin/forum/check')"}
{if condition="checkRuleButton('forum/check')"}
<input type="checkbox" name="check" lay-skin="switch" lay-filter="forumcheck" lay-text="通过|{{# if(d.check == -1){ }}禁止{{# } }} {{# if(d.check == 0){ }}待审{{# } }}" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >
{else /}<button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-disabled">无权限</button>{/if}
</script>
<script type="text/html" id="table-forum-list">
{if condition="checkRuleButton('admin/forum/listdel')"}
{if condition="checkRuleButton('forum/listdel')"}
<!--a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="edit" ><i class="layui-icon layui-icon-edit"></i>编辑</a-->
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
{else /}<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i></a>{/if}
@ -117,7 +117,7 @@ var forumList = "{:url('Forum/list')}",
//监听搜索
form.on('submit(LAY-app-forumlist-search)', function(data){
var field = data.field;
$.post("{:url('admin/Forum/list')}",field);
$.post("{:url('Forum/list')}",field);
//执行重载
table.reload('LAY-app-forum-list', {
where: field
@ -147,7 +147,7 @@ var forumList = "{:url('Forum/list')}",
//执行 Ajax 后重载
$.post("{:url('admin/Forum/listdel')}",{"id": ids},function(res){
$.post("{:url('Forum/listdel')}",{"id": ids},function(res){
if(res.code == 0){
layer.msg('删除成功', {
icon: 1
@ -171,7 +171,7 @@ var forumList = "{:url('Forum/list')}",
//执行帖子审核
$.ajax({
type:'post',
url:"{:url('admin/Forum/check')}",
url:"{:url('Forum/check')}",
data:{id:data.id,status:status},
dataType:'json',
success:function(res){

View File

@ -47,11 +47,11 @@
<a href="{$domain}/jie/{{d.cid}}.html" target="_blank">{{d.cardid}}</a>
</script>
<script type="text/html" id="buttonCheck">
{if condition="checkRuleButton('admin/forum/recheck')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="recheck" lay-text="通过|{{# if(d.check == -1){ }}禁止{{# } }} {{# if(d.check == 0){ }}待审{{# } }}" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >
{if condition="checkRuleButton('forum/recheck')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="recheck" lay-text="通过|{{# if(d.check == -1){ }}禁止{{# } }} {{# if(d.check == 0){ }}待审{{# } }}" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >
{else /}<button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-disabled">无权限</button>{/if}
</script>
<script type="text/html" id="table-forum-replys">
{if condition="checkRuleButton('admin/forum/redel')"}
{if condition="checkRuleButton('forum/redel')"}
<!--a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a-->
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
{else / }<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i>删除</a>{/if}
@ -85,7 +85,7 @@ var forumList = "{:url('Forum/list')}",
//监听搜索
form.on('submit(LAY-app-forumreply-search)', function(data){
var field = data.field;
$.post("{:url('admin/Forum/replys')}",field);
$.post("{:url('Forum/replys')}",field);
//执行重载
table.reload('LAY-app-forumreply-list', {
where: field
@ -94,7 +94,7 @@ var forumList = "{:url('Forum/list')}",
//状态选择
form.on('select(fourm-check)',function(data){
$.post("{:url('admin/Forum/replys')}",{"status":data.value});
$.post("{:url('Forum/replys')}",{"status":data.value});
//执行重载
table.reload('LAY-app-forumreply-list', {
where: {
@ -134,7 +134,7 @@ var forumList = "{:url('Forum/list')}",
//执行回帖审核
$.ajax({
type:'post',
url:"{:url('admin/Forum/recheck')}",
url:"{:url('Forum/recheck')}",
data:{id:data.id,status:status},
dataType:'json',
success:function(res){

View File

@ -18,7 +18,7 @@ overflow: visible;
<div class="layui-fluid">
<div class="layui-card">
<div class="layui-card-header layuiadmin-card-header-auto">
{if condition="checkRuleButton('admin/forum/addtags')"}
{if condition="checkRuleButton('forum/addtags')"}
<button class="layui-btn layuiadmin-btn-tags" data-type="add">添加</button>
{/if}
</div>
@ -32,14 +32,14 @@ overflow: visible;
</select>
</script>
<script type="text/html" id="buttonHot">
{if condition="checkRuleButton('admin/Forum/tagshot')"}<input type="checkbox" name="is_hot" lay-skin="primary" lay-filter="menu-show" {{# if(d.is_hot ==1){ }}checked value="0"{{# } else { }}value="1"{{# } }} id="{{d.id}}" >
{if condition="checkRuleButton('Forum/tagshot')"}<input type="checkbox" name="is_hot" lay-skin="primary" lay-filter="menu-show" {{# if(d.is_hot ==1){ }}checked value="0"{{# } else { }}value="1"{{# } }} id="{{d.id}}" >
{else /}<input type="checkbox" title="禁用" disabled> {/if}
</script>
<script type="text/html" id="layuiadmin-app-cont-tagsbar">
{if condition="checkRuleButton('admin/forum/tagsform')"}
{if condition="checkRuleButton('forum/tagsform')"}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
{else /}<a class="layui-btn layui-btn-disabled layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-edit"></i></a>{/if}
{if condition="checkRuleButton('admin/forum/tagsdelete')"}
{if condition="checkRuleButton('forum/tagsdelete')"}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
{else /}<a class="layui-btn layui-btn-disabled layui-btn-danger layui-btn-xs"><i class="layui-icon layui-icon-delete"></i></a>{/if}
</script>
@ -89,7 +89,7 @@ overflow: visible;
$.ajax({
type:"post",
url:"{:url('admin/Forum/tagsform')}",
url:"{:url('Forum/tagsform')}",
data:{"sort":sort,"catename":tags,"ename":ename,"detpl":detpl,"icon":icon,"desc":desc},
daType:"json",
success:function (data){
@ -110,7 +110,7 @@ overflow: visible;
//详情页模板选择控制
form.on('select(detpl)', function(data){
var detpl = data.value;
$.post("{:url('admin/Forum/tplSet')}",{"id":data.elem.id,"detpl":detpl});
$.post("{:url('Forum/tplSet')}",{"id":data.elem.id,"detpl":detpl});
//执行重载
table.reload('LAY-app-content-tags', {
where: detpl
@ -124,7 +124,7 @@ overflow: visible;
data.value = data.checked ? 1 : 0;
$.ajax({
type:'post',
url:"{:url('admin/Forum/tagshot')}",
url:"{:url('Forum/tagshot')}",
data:{"id":data.id,"is_hot":data.value,},
dataType:'json',
success:function(data){

View File

@ -33,7 +33,7 @@
</div>
<div class="layui-form-item" style="margin-bottom: 20px;">
<input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
<a href="{:url('admin/login/forget')}" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码?</a>
<a href="{:url('login/forget')}" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码?</a>
</div>
<div class="layui-form-item">
<input type="hidden" class="layui-hide" name="__token__" value="{:token()}" />
@ -44,7 +44,7 @@
<a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
<a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
<a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>
<a href="{:url('admin/login/reg')}" class="layadmin-user-jump-change layadmin-link">注册帐号</a>
<a href="{:url('login/reg')}" class="layadmin-user-jump-change layadmin-link">注册帐号</a>
</div-->
{:hook('socialhook')}
</div>

View File

@ -108,7 +108,7 @@
,icon: 1
,time: 1000
}, function(){
location.hash = '/admin/user/login'; //跳转到登入页
location.hash = "{:url('user/login')}"; //跳转到登入页
});
}
});

View File

@ -35,7 +35,7 @@
</div>
</div>
<div class="layui-form-item">
{if condition="checkRuleButton('admin/notice/add')"}
{if condition="checkRuleButton('notice/add')"}
<button type="submit" class="layui-btn " lay-filter="notice-add" lay-submit id="notice-add">立即发布</button>
{else /}<button type="submit" class="layui-btn layui-btn-disabled">立即发布</button>{/if}
</div>
@ -50,10 +50,10 @@
<div class="layui-form-item">
<table id="notice-list" lay-filter="notice-list"></table>
<script type="text/html" id="notice-tool">
{if condition="checkRuleButton('admin/notice/edit')"}
{if condition="checkRuleButton('notice/edit')"}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
{else /}<a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-edit"></i>编辑</a>{/if}
{if condition="checkRuleButton('admin/notice/delete')"}
{if condition="checkRuleButton('notice/delete')"}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
{else /}<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i>删除</a>{/if}
</script>

View File

@ -1,3 +1,4 @@
<!-- 侧边菜单 -->
<div class="layui-side layui-side-menu">
<div class="layui-side-scroll">
@ -28,13 +29,13 @@
<a lay-href="{:url('User/list')}">网站用户1</a>
</dd>
<dd>
<a lay-href="{:url('admin/admin/adminList')}">后台管理员</a>
<a lay-href="{:url('adminList')}">后台管理员</a>
</dd>
<dd>
<a lay-href="{:url('admin/authgroup/role')}">角色管理</a>
<a lay-href="{:url('authgroup/role')}">角色管理</a>
</dd>
<dd>
<a lay-href="{:url('admin/authrule/index')}">权限管理</a>
<a lay-href="{:url('authrule/index')}">权限管理</a>
</dd>
</dl>
</li-->

View File

@ -1,32 +1,72 @@
{extend name="public/base" /}
{block name="body"}
<div class="layui-fluid" id="component-tabs">
<div class="layui-fluid" id="component-tabs">
<div class="layui-row">
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-body">
<div class="layui-tab layui-tab-card" lay-filter="seo-tabs-brief">
<ul class="layui-tab-title">
<li class="layui-this" lay-id="push">百度推送</li>
<li lay-id="map">站点地图</li>
<ul class="layui-tab-title">
<li lay-id="config"><span style="color:red">* </span>接口配置</li>
<li class="layui-this" lay-id="push">百度推送</li>
<li lay-id="map">站点地图</li>
<li lay-id="robots">robots</li>
<li lay-id="config">* 接口配置</li>
</ul>
</ul>
<div class="layui-tab-content">
<div class="layui-tab-item layui-show">
<div class="layui-form" wid100 lay-filter="push">
<div class="layui-form-item">
<label class="layui-form-label">链接提交</label>
<div class="layui-input-block">
{if condition="checkRuleButton('Seo/push')"}
<button class="layui-btn" lay-submit lay-filter="search_push">提交推送</button>
{else /}
<button class="layui-btn layui-btn-disabled">提交推送</button>
{/if}
<div class="layui-tab-item">
<div class="layui-form" wid100 lay-filter="config">
<div class="layui-form-item">
<label class="layui-form-label">key</label>
<div class="layui-input-inline">
<input type="text" name="client_id" value="{:config('taoler.baidu.client_id')}" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">百度分词API Key</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">secret</label>
<div class="layui-input-inline">
<input type="text" name="client_secret" value="{:config('taoler.baidu.client_secret')}" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">百度分词Secret Key</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">推送接口</label>
<div class="layui-input-inline">
<input type="text" name="push_api" value="{:config('taoler.baidu.push_api')}" placeholder="http://完整的接口地址" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">接口调用地址:http://data.zz.baidu.com/urls?site=https://www.youurl.com&token=yuotoken</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="baidu_config">确认保存</button>
</div>
</div>
</div>
</div>
<div class="layui-tab-item layui-show">
<div class="layui-form" wid100 lay-filter="push">
<div class="layui-form-item">
<label class="layui-form-label">推送范围</label>
<div class="layui-input-inline" style="width: 100px;">
<input type="text" name="start_id" value="" placeholder="开始ID" class="layui-input" >
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline" style="width: 100px;">
<input type="text" name="end_id" placeholder="结束ID" autocomplete="off" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">帖子ID范围,如果不填,默认全站提交</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">推送至API</label>
<div class="layui-input-block">
{if condition="checkRuleButton('Seo/push')"}
<button class="layui-btn" lay-submit lay-filter="search_push">提交推送</button>
{else /}
<button class="layui-btn layui-btn-disabled">提交推送</button>
{/if}
</div>
</div>
</div>
</div>
</div>
<div class="layui-tab-item">
@ -76,36 +116,7 @@
</div>
</div>
</div>
<div class="layui-tab-item">
<div class="layui-form" wid100 lay-filter="config">
<div class="layui-form-item">
<label class="layui-form-label">key</label>
<div class="layui-input-inline">
<input type="text" name="client_id" value="{:config('taoler.baidu.client_id')}" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">百度分词API Key</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">secret</label>
<div class="layui-input-inline">
<input type="text" name="client_secret" value="{:config('taoler.baidu.client_secret')}" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">百度分词Secret Key</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">收录token</label>
<div class="layui-input-inline">
<input type="text" name="push_api" value="{:config('taoler.baidu.push_api')}" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux">百度准入密钥</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="baidu_config">确认保存</button>
</div>
</div>
</div>
</div>
</div>
</div>
@ -131,8 +142,8 @@
// baidu push
form.on('submit(search_push)', function(data){
//var field = data.field;
$.post("{:url('seo/push')}",function(res){
var field = data.field;
$.post("{:url('seo/push')}",field,function(res){
if(res.code == 0){
layer.msg(res.msg,{icon:6,tiye:2000
});

View File

@ -38,7 +38,7 @@
<input type="tel" name="score" lay-verify="required" placeholder="获得积分" autocomplete="off" class="layui-input">
</div>
<div class="layui-input-inline">
{if condition="checkRuleButton('admin/Sign/add')"}
{if condition="checkRuleButton('Sign/add')"}
<input type="submit" class="layui-btn" lay-submit lay-filter="sign-rule-submit" id="sign-rule-submit" value="立即提交">
{else /}<input type="submit" class="layui-btn layui-btn-disabled" value="立即提交">{/if}
</div>
@ -47,10 +47,10 @@
<div class="layui-form-item">
<table id="sign-rule" lay-filter="sign-rule"></table>
<script type="text/html" id="sign-rule-button">
{if condition="checkRuleButton('admin/Sign/edit')"}
{if condition="checkRuleButton('Sign/edit')"}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
{else /}<a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-edit"></i>编辑</a>{/if}
{if condition="checkRuleButton('admin/Sign/delete')"}
{if condition="checkRuleButton('Sign/delete')"}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
{else /}<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i>删除</a>{/if}
</script>
@ -78,7 +78,7 @@
<input type="tel" name="score" lay-verify="required" placeholder="积分区间:0-99" autocomplete="off" class="layui-input">
</div>
<div class="layui-input-inline">
{if condition="checkRuleButton('admin/Vip/add')"}
{if condition="checkRuleButton('Vip/add')"}
<input type="submit" class="layui-btn" lay-submit lay-filter="vip-rule-submit" id="vip-rule-submit" value="立即提交">
{else /}<input type="submit" class="layui-btn layui-btn-disabled" value="立即提交">{/if}
</div>
@ -88,10 +88,10 @@
<div class="layui-form-item">
<table id="vip-rule" lay-filter="vip-rule"></table>
<script type="text/html" id="vip-rule-button">
{if condition="checkRuleButton('admin/Vip/vipEdit')"}
{if condition="checkRuleButton('Vip/vipEdit')"}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
{else /}<a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-edit"></i></a>{/if}
{if condition="checkRuleButton('admin/Vip/delete')"}
{if condition="checkRuleButton('Vip/delete')"}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
{else /}<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i></a>{/if}
</script>
@ -160,7 +160,7 @@
var field = data.field;
$.ajax({
type:"post",
url:"{:url('admin/Vip/add')}",
url:"{:url('Vip/add')}",
data:field,
daType:"json",
success:function (data){

View File

@ -13,6 +13,7 @@
<li lay-id="email">邮箱服务</li>
<li lay-id="config">服务配置</li>
<li lay-id="domain">域名绑定</li>
<li lay-id="url_rewrite">URL美化</li>
</ul>
<div class="layui-tab-content">
<div class="layui-tab-item layui-show">
@ -44,7 +45,7 @@
<label class="layui-form-label">LOGO</label>
<div class="layui-input-block">
<span><img src="{$sysInfo.logo}" hight="40" width="50" ></span>
{if condition="checkRuleButton('admin/set/upload')"}
{if condition="checkRuleButton('set/upload')"}
<button type="button" class="layui-btn layui-btn-normal" id="logo-img">选择文件</button>
<button type="button" class="layui-btn" id="logo-upload-button">开始上传</button>
{else /}<button type="button" class="layui-btn layui-btn-normal layui-btn-disabled">选择文件</button>{/if}
@ -121,7 +122,7 @@
</div>
<div class="layui-form-item">
<div class="layui-input-block">
{if condition="checkRuleButton('admin/Set/website')"}
{if condition="checkRuleButton('Set/website')"}
<button class="layui-btn" lay-submit lay-filter="set_website">确认保存</button>
{else /}<button class="layui-btn layui-btn-disabled">确认保存</button>{/if}
</div>
@ -164,7 +165,7 @@
</div>
<div class="layui-form-item">
<div class="layui-input-block">
{if condition="checkRuleButton('admin/Set/email')"}
{if condition="checkRuleButton('Set/email')"}
<button class="layui-btn" lay-submit lay-filter="set_system_email">确认保存</button>
{else /}<button class="layui-btn layui-btn-disabled">确认保存</button>{/if}
</div>
@ -289,17 +290,38 @@
<div class="layui-form-item">
<div class="layui-input-block">
{if condition="checkRuleButton('admin/Set/email')"}
{if condition="checkRuleButton('Set/email')"}
<button class="layui-btn" lay-submit lay-filter="set_system_domain">确认保存</button>
{else /}<button class="layui-btn layui-btn-disabled">确认保存</button>{/if}
</div>
</div>
</div>
</div>
</div>
<div class="layui-tab-item">
<div class="layui-form" wid100 lay-filter="url_rewrite">
<div class="layui-form-item">
<label class="layui-form-label">帖子别名</label>
<div class="layui-input-inline">
<input type="text" name="article_as" required value="{:config('taoler.url_rewrite.article_as')}" class="layui-input">
</div>
<div id="artdesc" class="layui-form-mid layui-word-aux">www.aieok.com/article/1.html</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">分类别名</label>
<div class="layui-input-inline">
<input type="text" name="cate_as" required value="{:config('taoler.url_rewrite.cate_as')}" class="layui-input">
</div>
<div id="catedesc" class="layui-form-mid layui-word-aux">www.aieok.com/cate/ask.html</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="set_url_rewrite">确认保存</button>
</div>
</div>
</div>
</div>
</div>
</div>
@ -327,7 +349,7 @@
//LOGO选完文件后不自动上传
upload.render({
elem: '#logo-img'
,url: "{:url('admin/set/upload')}"
,url: "{:url('set/upload')}"
,data: {type:'image'}
,auto: false
,exts: 'jpg|png|gif|bmp|jpeg'
@ -348,7 +370,7 @@
//网站配置
form.on('submit(set_system_config)', function(data){
var field = data.field;
$.post("{:url('admin/set/config')}",field,function(res){
$.post("{:url('set/config')}",field,function(res){
if(res.code == 0){
layer.msg(res.msg,{icon:6,tiye:2000
});
@ -361,7 +383,7 @@
//邮箱发送测试码
form.on('submit(test_system_email)', function(data){
var field = data.field;
$.post("{:url('admin/set/sendMailCode')}",field,function(res){
$.post("{:url('set/sendMailCode')}",field,function(res){
if(res.code == 0){
layer.msg(res.msg,{icon:6,tiye:2000
});
@ -375,7 +397,7 @@
//邮箱激活
form.on('submit(active_system_email)', function(data){
var field = data.field;
$.post("{:url('admin/set/activeMailServer')}",field,function(res){
$.post("{:url('set/activeMailServer')}",field,function(res){
if(res.code == 0){
layer.msg(res.msg,{icon:6,tiye:2000
});
@ -389,7 +411,7 @@
//网站配置
form.on('submit(set_system_domain)', function(data){
var field = data.field;
$.post("{:url('admin/set/setDomain')}",field,function(res){
$.post("{:url('set/setDomain')}",field,function(res){
if(res.code == 0){
layer.msg(res.msg,{icon:6,tiye:2000
}, function(){
@ -402,6 +424,33 @@
return false;
});
// URL美化
form.on('submit(set_url_rewrite)', function(data){
var field = data.field;
$.post("{:url('set/setUrl')}",field,function(res){
if(res.code == 0){
layer.msg(res.msg,{icon:6,tiye:2000
}, function(){
//parent.location.href = '/';
});
} else {
layer.open({title:"设置失败",content:res.msg,icon:5,anim:6});
}
});
return false;
});
// 获取描述的内容
$("input[name='article_as']").bind('input propertychange', function(){
var content = $(this).val()
$('#artdesc').html('如www.aieok.com/'+ content +'/1.html');
})
$("input[name='cate_as']").bind('input propertychange', function(){
var content = $(this).val()
$('#catedesc').html('如www.aieok.com/'+ content +'/ask.html');
})
form.on('switch(domain_check)', function(data){
var data = data.elem;
status = data.checked ? 'on' : 'off';
@ -409,7 +458,7 @@
$('#set_domain').removeClass('layui-hide');
} else {
$('#set_domain').addClass('layui-hide');
$.post("{:url('admin/set/setDomain')}",{"domain_check":status},function(res){
$.post("{:url('set/setDomain')}",{"domain_check":status},function(res){
if(res.code == 0){
layer.msg(res.msg,{icon:6,tiye:2000
}, function(){

View File

@ -72,7 +72,7 @@
</div>
<div class="layui-form-item">
<div class="layui-input-block">
{if condition="checkRuleButton('admin/Admin/infoSet')"}
{if condition="checkRuleButton('Admin/infoSet')"}
<button class="layui-btn" lay-submit lay-filter="setmyinfo">确认修改</button>
{else /}
<button class="layui-btn layui-btn-disabled">确认修改</button>

View File

@ -1,3 +1,12 @@
<!--
* @Author: TaoLer <alipey_tao@qq.com>
* @Date: 2021-12-06 16:04:50
* @LastEditTime: 2022-04-19 17:11:28
* @LastEditors: TaoLer
* @Description: 搜索引擎SEO优化设置
* @FilePath: \TaoLer\app\admin\view\set\user\repass.html
* Copyright (c) 2020~2022 http://www.aieok.com All rights reserved.
-->
{extend name="public/base" /}
{block name="body"}
@ -30,7 +39,7 @@
</div>
<div class="layui-form-item">
<div class="layui-input-block">
{if condition="checkRuleButton('admin/Admin/repassSet')"}
{if condition="checkRuleButton('Admin/repassSet')"}
<button class="layui-btn" lay-submit lay-filter="setmypass">确认修改</button>
{else /}
<button class="layui-btn layui-btn-disabled">确认修改</button>

View File

@ -41,7 +41,7 @@
<th>{$vo.slid_status ?'显示':'禁止'}</th>
<th>
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" id-data="{$vo.id}"><i class="layui-icon layui-icon-edit"></i></a>
{if condition="checkRuleButton('admin/Slider/delete')"}
{if condition="checkRuleButton('Slider/delete')"}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" id-data="{$vo.id}"><i class="layui-icon layui-icon-delete"></i></a>
{else /}<a class="layui-btn layui-btn-disabled layui-btn-danger layui-btn-xs"><i class="layui-icon layui-icon-delete"></i></a>{/if}
</th>
@ -95,7 +95,7 @@
//提交 Ajax 成功后,静态更新表格中的数据
$.ajax({
type:"post",
url:"{:url('admin/slider/add')}",
url:"{:url('slider/add')}",
data:{"slid_type":field.slid_type,"slid_name":field.slid_name,"slid_color":field.slid_color,"slid_start":field.slid_start,"slid_over":field.slid_over,"slid_href":field.slid_href,"slid_img":field.slid_img},
daType:"json",
success:function (data){
@ -145,7 +145,7 @@
//提交 Ajax 成功后,静态更新表格中的数据
$.ajax({
type:"post",
url:"{:url('admin/slider/edit')}",
url:"{:url('slider/edit')}",
data:{"id":id,"slid_type":field.slid_type,"slid_name":field.slid_name,"slid_color":field.slid_color,"slid_start":field.slid_start,"slid_over":field.slid_over,"slid_href":field.slid_href,"slid_img":field.slid_img},
daType:"json",
success:function (data){
@ -180,7 +180,7 @@
//提交 Ajax 成功后,静态更新表格中的数据
$.ajax({
type:"post",
url:"{:url('admin/slider/delete')}",
url:"{:url('slider/delete')}",
data:{"id":id},
daType:"json",
success:function (data){

View File

@ -17,7 +17,7 @@
</div>
<div class="layui-input-inline layui-input-company"><button style="float: left;" type="button" class="layui-btn layui-btn-sm" id="upgrade-key">保存</button></div>
<div class="layui-form-mid layui-word-aux" >无Key不能升级</div>
<div class="layui-form-mid layui-word-aux " ><a href="http://bbs.aieok.com/Api/key.html" target="_blank">去官网申请Key</a></div>
<div class="layui-form-mid layui-word-aux " ><a href="https://www.aieok.com/bbs/Api/key.html" target="_blank">去官网申请Key</a></div>
</div>
{else /}
<div class="layui-form-item">
@ -27,7 +27,7 @@
</div>
<div class="layui-form-mid layui-word-aux " ><span style="color:red">{$ver_num.key}</span></div>
<div class="layui-input-inline layui-input-company">
{if condition="checkRuleButton('admin/Upgrade/keyedit')"}
{if condition="checkRuleButton('Upgrade/keyedit')"}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" id-data="{:url('upgrade/keyedit')}" ><i class="layui-icon layui-icon-edit"></i>修改?</a>
{else /}<a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" ><i class="layui-icon layui-icon-edit"></i>修改?</a>{/if}
</div>
@ -36,7 +36,7 @@
<label class="layui-form-label">在线升级</label>
<div class="layui-input-inline layui-input-company" id="ver_nums" >当前版本Taoler v_{:config('taoler.version')}</div>
<div class="layui-upload">
{if condition="checkRuleButton('admin/Upgrade/check')"}
{if condition="checkRuleButton('Upgrade/check')"}
<button type="button" class="layui-btn layui-btn-sm" data-url="{$ver_num.upcheck_url}" id="upload-check">检查更新</button>
{else /}<button type="button" class="layui-btn layui-btn-sm layui-btn-disabled">检查更新</button>{/if}
</div>
@ -44,7 +44,7 @@
<div class="layui-form-item">
<label class="layui-form-label">手动更新</label>
<div class="layui-upload">
{if condition="checkRuleButton('admin/Upgrade/uploadzip')"}
{if condition="checkRuleButton('Upgrade/uploadzip')"}
<button type="button" class="layui-btn layui-btn-sm" id="select-file">选择文件</button>
<button type="button" class="layui-btn layui-btn-sm" id="upgrade-sys-button">开始升级</button>
{else /}<button type="button" class="layui-btn layui-btn-sm layui-btn-disabled">无权限</button>{/if}
@ -91,7 +91,7 @@
shade: [0.2, '#000'],
//time: 2000,
});
$.get("{:url('admin/upgrade/check')}",function (data){
$.get("{:url('upgrade/check')}",function (data){
if (data.code == 0) {
//已件最新版本
layer.close(loading);
@ -130,7 +130,7 @@
//更新
function uploads(){
var load = layer.load(); //loading
$.get("{:url('admin/upgrade/upload')}",function (data){
$.get("{:url('upgrade/upload')}",function (data){
if (data.code == 0) {
layer.close(load);
layer.msg(data.msg,{
@ -151,7 +151,7 @@
//手动更新,选完文件后不自动上传
upload.render({
elem: '#select-file'
,url: "{:url('admin/upgrade/uploadzip')}"
,url: "{:url('upgrade/uploadzip')}"
,data: {type:'zip'}
,accept: 'file'
,acceptMime: 'application/zip'
@ -198,7 +198,7 @@
$.ajax({
type:"post",
url:"{:url('admin/upgrade/key')}",
url:"{:url('upgrade/key')}",
data:{"key":key},
daType:"json",
success:function (data){
@ -245,7 +245,7 @@
//提交 Ajax 成功后,静态更新表格中的数据
$.ajax({
type:"post",
url:"{:url('admin/upgrade/keyedit')}",
url:"{:url('upgrade/keyedit')}",
data:{"key":field.key,"upcheck_url":field.upcheck_url,"upgrade_url":field.upgrade_url},
daType:"json",
success:function (data){

View File

@ -1,3 +1,12 @@
<!--
* @Author: TaoLer <alipey_tao@qq.com>
* @Date: 2021-12-06 16:04:50
* @LastEditTime: 2022-04-18 14:11:27
* @LastEditors: TaoLer
* @Description: 搜索引擎SEO优化设置
* @FilePath: \TaoLer\app\admin\view\upgrade\keyedit.html
* Copyright (c) 2020~2022 http://www.aieok.com All rights reserved.
-->
{extend name="public/base" /}
{block name="body"}
@ -24,7 +33,7 @@
<div class="layui-form-item">
<label class="layui-form-label">申请key?</label>
<div class="layui-input-inline">
<div class="layui-form-mid layui-word-aux " ><a href="http://bbs.aieok.com" target="_blank">更换网址,请去官网重新申请key</a></div>
<div class="layui-form-mid layui-word-aux " ><a href="https://www.aieok.com/bbs/Api/key.html" target="_blank">更换网址,请去官网重新申请key</a></div>
<div class="layui-form-mid layui-word-aux " ><span>未通知api接口变更,请不要私自更改api否则无法升级</span></div>
</div>
</div>

View File

@ -74,21 +74,21 @@
{{# if(d.id == '1'){ }}
<input type="checkbox" name="check" lay-skin="switch" disabled lay-text="通过|禁用" value="1" checked id="{{d.id}}">
{{# } else { }}
{if condition="checkRuleButton('admin/user/check')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="usercheck" lay-text="通过|{{# if(d.check == -1){ }}禁止{{# } }} {{# if(d.check == 0){ }}待审{{# } }}" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >{else}<button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-disabled">无权限</button>{/if}
{if condition="checkRuleButton('user/check')"}<input type="checkbox" name="check" lay-skin="switch" lay-filter="usercheck" lay-text="通过|{{# if(d.check == -1){ }}禁止{{# } }} {{# if(d.check == 0){ }}待审{{# } }}" {{# if(d.check == 1){ }} checked {{# } }} id="{{d.id}}" >{else}<button class="layui-btn layui-btn-xs layui-btn-radius layui-btn-disabled">无权限</button>{/if}
{{# } }}
</script>
<script type="text/html" id="buttonAuth">
{{# if(d.id == '1'){ }}
<input type="checkbox" name="auth" lay-skin="primary" checked disabled >
{{# } else { }}
{if condition="checkRuleButton('admin/user/auth')"}<input type="checkbox" name="auth" lay-skin="primary" lay-filter="auth" {{# if(d.auth ==1){ }}checked value="0"{{# } else { }}value="1"{{# } }} id="{{d.id}}" >{else}<button class="layui-btn layui-btn-xs layui-btn-disabled">无权限</button>{/if}
{if condition="checkRuleButton('user/auth')"}<input type="checkbox" name="auth" lay-skin="primary" lay-filter="auth" {{# if(d.auth ==1){ }}checked value="0"{{# } else { }}value="1"{{# } }} id="{{d.id}}" >{else}<button class="layui-btn layui-btn-xs layui-btn-disabled">无权限</button>{/if}
{{# } }}
</script>
<script type="text/html" id="table-useradmin-webuser">
{if condition="checkRuleButton('admin/user/useredit')"}
{if condition="checkRuleButton('user/useredit')"}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" id={{ d.id }}><i class="layui-icon layui-icon-edit"></i>编辑</a>
{else /}<a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-edit"></i>编辑</a>{/if}
{if condition="checkRuleButton('admin/user/delete')"}
{if condition="checkRuleButton('user/delete')"}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" id={{ d.id }}><i class="layui-icon layui-icon-delete"></i>删除</a>
{else /}<a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled"><i class="layui-icon layui-icon-delete"></i>删除</a>{/if}
</script>
@ -126,7 +126,7 @@
//监听搜索
form.on('submit(LAY-user-front-search)', function(data){
var field = data.field;
$.post("{:url('admin/User/list')}",field);
$.post("{:url('User/list')}",field);
//执行重载
table.reload('LAY-user-manage', {
where: field
@ -183,7 +183,7 @@
//提交 Ajax 成功后,静态更新表格中的数据
$.ajax({
type:"post",
url:"{:url('admin/User/userform')}",
url:"{:url('User/userform')}",
data:{"name":field.username,"phone":field.phone,"email":field.email,"user_img":field.avatar,"sex":field.sex},
daType:"json",
success:function (data){
@ -219,7 +219,7 @@
//执行用户审核
$.ajax({
type:'post',
url:"{:url('admin/User/check')}",
url:"{:url('User/check')}",
data:{"id":data.id,"status":status},
dataType:'json',
success:function(res){
@ -249,7 +249,7 @@
var auth = data.checked ? 1 : 0;
$.ajax({
type:'post',
url:"{:url('admin/User/auth')}",
url:"{:url('User/auth')}",
data:{"id":data.id,"auth":auth},
dataType:'json',
success:function(data){

View File

@ -1,22 +1,27 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
/*
* @Author: TaoLer <alipey_tao@qq.com>
* @Date: 2021-12-06 16:04:50
* @LastEditTime: 2022-04-19 13:19:28
* @LastEditors: TaoLer
* @Description: 搜索引擎SEO优化设置
* @FilePath: \TaoLer\app\index\route\route.php
* Copyright (c) 2020~2022 http://www.aieok.com All rights reserved.
*/
use think\facade\Route;
//详情页URL别称
$detail_as = config('taoler.url_rewrite.article_as');
//分类别称
$cate_as = config('taoler.url_rewrite.cate_as');
Route::get('captcha/[:config]','\\think\\captcha\\CaptchaController@index');
Route::rule('/', 'index'); // 首页访问路由
Route::group(function () {
Route::get('jie/:id', 'article/detail');
Route::get('column/<ename>$','article/cate');
Route::get('column/<ename>/<type>$', 'article/cate')->name('cate_type');
Route::rule('column/<ename>/<type>/<page>', 'article/cate')->name('cate_page');
Route::group(function () use($detail_as,$cate_as){
Route::get($detail_as .'/:id', 'article/detail');
Route::get($cate_as.'/<ename>$','article/cate');
Route::get($cate_as.'/<ename>/<type>$', 'article/cate')->name('cate_type');
Route::rule($cate_as.'/<ename>/<type>/<page>', 'article/cate')->name('cate_page');
Route::rule('add','Article/add');
Route::rule('tags','Article/tags')->allowCrossDomain();
Route::rule('edit/[:id]','Article/edit');

View File

@ -265,7 +265,7 @@ INSERT INTO `tao_auth_rule` VALUES ('96', 'Database/delete', '备份删除', '',
INSERT INTO `tao_auth_rule` VALUES ('97', 'addons', '插件', '', '1', '1', '0', '0', 'layui-icon-flag', '1', '2', '', '1635757328', '1635757632', '0');
INSERT INTO `tao_auth_rule` VALUES ('98', 'Addons/index', '插件市场', '', '1', '1', '97', '1', '', '1', '0', '', '1635757426', '0', '0');
INSERT INTO `tao_auth_rule` VALUES ('99', 'Addons/addonsList', '插件列表', '', '1', '1', '98', '2', '', '-1', '0', '', '1638775199', '0', '0');
INSERT INTO `tao_auth_rule` VALUES ('111','Seo/index','SEO','1','1','0','0','layui-icon-component','1','7','','1649829142','0','0');
INSERT INTO `tao_auth_rule` VALUES ('111','Seo/index','SEO', '', '1','1','0','0','layui-icon-component','1','7','','1649829142','0','0');
-- ----------------------------
-- Table structure for tao_cate

View File

@ -29,7 +29,8 @@
"wamkj/thinkphp6.0-databackup": "^1.0",
"taoser/think-addons": "^1.0",
"liliuwei/thinkphp-social": "^1.3",
"taoser/think-setarr": "^0.0.3"
"taoser/think-setarr": "^0.0.3",
"topthink/think-migration": "^3.0"
},
"require-dev": {
"symfony/var-dumper": "^4.2",

68
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "52d2121e202720cc23a0528605fafe09",
"content-hash": "9b81a97861a9ca21e9a9308a2587c14f",
"packages": [
{
"name": "firebase/php-jwt",
@ -210,16 +210,16 @@
},
{
"name": "league/mime-type-detection",
"version": "1.10.0",
"version": "1.11.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/mime-type-detection.git",
"reference": "3e4a35d756eedc67096f30240a68a3149120dae7"
"reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/3e4a35d756eedc67096f30240a68a3149120dae7",
"reference": "3e4a35d756eedc67096f30240a68a3149120dae7",
"url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/ff6248ea87a9f116e78edd6002e39e5128a0d4dd",
"reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd",
"shasum": ""
},
"require": {
@ -250,7 +250,7 @@
"description": "Mime-type detection for Flysystem",
"support": {
"issues": "https://github.com/thephpleague/mime-type-detection/issues",
"source": "https://github.com/thephpleague/mime-type-detection/tree/1.10.0"
"source": "https://github.com/thephpleague/mime-type-detection/tree/1.11.0"
},
"funding": [
{
@ -262,7 +262,7 @@
"type": "tidelift"
}
],
"time": "2022-04-11T12:49:04+00:00"
"time": "2022-04-17T13:12:02+00:00"
},
{
"name": "liliuwei/thinkphp-social",
@ -1072,6 +1072,60 @@
},
"time": "2021-01-14T12:12:14+00:00"
},
{
"name": "topthink/think-migration",
"version": "v3.0.3",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-migration.git",
"reference": "5717d9e5f3ea745f6dbfd1e30b4402aaadff9a79"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-migration/zipball/5717d9e5f3ea745f6dbfd1e30b4402aaadff9a79",
"reference": "5717d9e5f3ea745f6dbfd1e30b4402aaadff9a79",
"shasum": ""
},
"require": {
"topthink/framework": "^6.0.0",
"topthink/think-helper": "^3.0.3"
},
"require-dev": {
"fzaninotto/faker": "^1.8"
},
"suggest": {
"fzaninotto/faker": "Required to use the factory builder (^1.8)."
},
"type": "library",
"extra": {
"think": {
"services": [
"think\\migration\\Service"
]
}
},
"autoload": {
"psr-4": {
"Phinx\\": "phinx/src/Phinx",
"think\\migration\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"support": {
"issues": "https://github.com/top-think/think-migration/issues",
"source": "https://github.com/top-think/think-migration/tree/v3.0.3"
},
"time": "2020-12-07T05:54:22+00:00"
},
{
"name": "topthink/think-multi-app",
"version": "v1.0.14",

View File

@ -2,7 +2,7 @@
/*
* @Author: TaoLer <alipey_tao@qq.com>
* @Date: 2021-12-06 16:04:50
* @LastEditTime: 2022-04-17 16:49:19
* @LastEditTime: 2022-04-19 16:49:29
* @LastEditors: TaoLer
* @Description: 搜索引擎SEO优化设置
* @FilePath: \TaoLer\config\app.php
@ -30,7 +30,7 @@ return [
'app_map' => [
//'bbs' => 'index',
//'*' => 'home',
//'admin' => 'admin',
//'admin1' => 'admin',
],
// 域名绑定(自动多应用模式有效)
'domain_bind' => [

View File

@ -2,9 +2,9 @@
/*
* @Author: TaoLer <alipey_tao@qq.com>
* @Date: 2021-12-06 16:04:50
* @LastEditTime: 2022-04-17 16:54:16
* @LastEditTime: 2022-04-19 16:48:27
* @LastEditors: TaoLer
* @Description: 搜索引擎SEO优化设
* @Description: 网站公共配
* @FilePath: \TaoLer\config\taoler.php
* Copyright (c) 2020~2022 http://www.aieok.com All rights reserved.
*/
@ -16,11 +16,13 @@ return [
// 应用名,此项不可更改
'appname' => 'TaoLer',
// 版本配置
'version' => '1.9.1',
'version' => '1.9.2',
// 加盐
'salt' => 'taoler',
// 数据库备份目录
'databasebackdir' => app()->getRootPath() .'data/',
'article_as' => 'aa',
'cate_as' => 'column',
// 配置
'config' =>[
'email_notice' => 0,
@ -36,20 +38,30 @@ return [
// 百度标签分词
'baidu' => [
'grant_type' => '',
'client_id' => '',
'client_secret' => '',
'client_id' => 'aa',
'client_secret' => 'aa',
'access_token' => '',
'push_api' => '',
'push_api' => 'http://',
],
// sitemap
'sitemap' => [
// 每次生成数量
'map_num' => '1000',
'map_time' => 'daily',
'map_level' => '0.5',
'write_id' => 0,
// 已生成id位标记
'write_id' => 12,
],
// URL美化
'url_rewrite' => [
// 详情url
'article_as' => 'article',
// 分类url
'cate_as' => 'column',
],
];

4
public/.gitignore vendored
View File

@ -1,2 +1,2 @@
!.gitignore
install.lock
install.lock
/home

View File

@ -5,6 +5,4 @@ Disallow: /index/user/
Disallow: /index/api/
Disallow: /index/login.html
Disallow: /index/reg.html
Disallow: /*?*
sitemap:http://www.test.com/2022-04-16_1.xml
sitemap:http://www.test.com/2022-04-16_2.xml
Disallow: /*?*

View File

@ -9,6 +9,7 @@ return array(
'wamkj\\thinkphp\\' => array($vendorDir . '/wamkj/thinkphp6.0-databackup/src'),
'think\\view\\driver\\' => array($vendorDir . '/topthink/think-view/src'),
'think\\trace\\' => array($vendorDir . '/topthink/think-trace/src'),
'think\\migration\\' => array($vendorDir . '/topthink/think-migration/src'),
'think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'),
'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),
'think\\app\\' => array($vendorDir . '/topthink/think-multi-app/src'),
@ -27,6 +28,7 @@ return array(
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
'Phinx\\' => array($vendorDir . '/topthink/think-migration/phinx/src/Phinx'),
'PHPMailer\\PHPMailer\\' => array($vendorDir . '/phpmailer/phpmailer/src'),
'League\\MimeTypeDetection\\' => array($vendorDir . '/league/mime-type-detection/src'),
'League\\Flysystem\\Cached\\' => array($vendorDir . '/league/flysystem-cached-adapter/src'),

View File

@ -27,6 +27,7 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2
array (
'think\\view\\driver\\' => 18,
'think\\trace\\' => 12,
'think\\migration\\' => 16,
'think\\composer\\' => 15,
'think\\captcha\\' => 14,
'think\\app\\' => 10,
@ -60,6 +61,7 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2
'Psr\\Http\\Message\\' => 17,
'Psr\\Container\\' => 14,
'Psr\\Cache\\' => 10,
'Phinx\\' => 6,
'PHPMailer\\PHPMailer\\' => 20,
),
'L' =>
@ -87,6 +89,10 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2
array (
0 => __DIR__ . '/..' . '/topthink/think-trace/src',
),
'think\\migration\\' =>
array (
0 => __DIR__ . '/..' . '/topthink/think-migration/src',
),
'think\\composer\\' =>
array (
0 => __DIR__ . '/..' . '/topthink/think-installer/src',
@ -163,6 +169,10 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2
array (
0 => __DIR__ . '/..' . '/psr/cache/src',
),
'Phinx\\' =>
array (
0 => __DIR__ . '/..' . '/topthink/think-migration/phinx/src/Phinx',
),
'PHPMailer\\PHPMailer\\' =>
array (
0 => __DIR__ . '/..' . '/phpmailer/phpmailer/src',

View File

@ -227,17 +227,17 @@
},
{
"name": "league/mime-type-detection",
"version": "1.10.0",
"version_normalized": "1.10.0.0",
"version": "1.11.0",
"version_normalized": "1.11.0.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/mime-type-detection.git",
"reference": "3e4a35d756eedc67096f30240a68a3149120dae7"
"reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/3e4a35d756eedc67096f30240a68a3149120dae7",
"reference": "3e4a35d756eedc67096f30240a68a3149120dae7",
"url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/ff6248ea87a9f116e78edd6002e39e5128a0d4dd",
"reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd",
"shasum": ""
},
"require": {
@ -249,7 +249,7 @@
"phpstan/phpstan": "^0.12.68",
"phpunit/phpunit": "^8.5.8 || ^9.3"
},
"time": "2022-04-11T12:49:04+00:00",
"time": "2022-04-17T13:12:02+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -270,7 +270,7 @@
"description": "Mime-type detection for Flysystem",
"support": {
"issues": "https://github.com/thephpleague/mime-type-detection/issues",
"source": "https://github.com/thephpleague/mime-type-detection/tree/1.10.0"
"source": "https://github.com/thephpleague/mime-type-detection/tree/1.11.0"
},
"funding": [
{
@ -1542,6 +1542,63 @@
},
"install-path": "../topthink/think-installer"
},
{
"name": "topthink/think-migration",
"version": "v3.0.3",
"version_normalized": "3.0.3.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-migration.git",
"reference": "5717d9e5f3ea745f6dbfd1e30b4402aaadff9a79"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-migration/zipball/5717d9e5f3ea745f6dbfd1e30b4402aaadff9a79",
"reference": "5717d9e5f3ea745f6dbfd1e30b4402aaadff9a79",
"shasum": ""
},
"require": {
"topthink/framework": "^6.0.0",
"topthink/think-helper": "^3.0.3"
},
"require-dev": {
"fzaninotto/faker": "^1.8"
},
"suggest": {
"fzaninotto/faker": "Required to use the factory builder (^1.8)."
},
"time": "2020-12-07T05:54:22+00:00",
"type": "library",
"extra": {
"think": {
"services": [
"think\\migration\\Service"
]
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Phinx\\": "phinx/src/Phinx",
"think\\migration\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"support": {
"issues": "https://github.com/top-think/think-migration/issues",
"source": "https://github.com/top-think/think-migration/tree/v3.0.3"
},
"install-path": "../topthink/think-migration"
},
{
"name": "topthink/think-multi-app",
"version": "v1.0.14",

View File

@ -5,7 +5,7 @@
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => 'f8f39741994332a33848a2cf4f58ade195aea126',
'reference' => '1250b449335a867caa1976e6117d3b3448b5d7bf',
'name' => 'taoser/taoler',
'dev' => true,
),
@ -38,12 +38,12 @@
'dev_requirement' => false,
),
'league/mime-type-detection' => array(
'pretty_version' => '1.10.0',
'version' => '1.10.0.0',
'pretty_version' => '1.11.0',
'version' => '1.11.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../league/mime-type-detection',
'aliases' => array(),
'reference' => '3e4a35d756eedc67096f30240a68a3149120dae7',
'reference' => 'ff6248ea87a9f116e78edd6002e39e5128a0d4dd',
'dev_requirement' => false,
),
'liliuwei/thinkphp-social' => array(
@ -160,7 +160,7 @@
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => 'f8f39741994332a33848a2cf4f58ade195aea126',
'reference' => '1250b449335a867caa1976e6117d3b3448b5d7bf',
'dev_requirement' => false,
),
'taoser/think-addons' => array(
@ -226,6 +226,15 @@
'reference' => '38ba647706e35d6704b5d370c06f8a160b635f88',
'dev_requirement' => false,
),
'topthink/think-migration' => array(
'pretty_version' => 'v3.0.3',
'version' => '3.0.3.0',
'type' => 'library',
'install_path' => __DIR__ . '/../topthink/think-migration',
'aliases' => array(),
'reference' => '5717d9e5f3ea745f6dbfd1e30b4402aaadff9a79',
'dev_requirement' => false,
),
'topthink/think-multi-app' => array(
'pretty_version' => 'v1.0.14',
'version' => '1.0.14.0',

View File

@ -730,6 +730,7 @@ class GeneratedExtensionToMimeTypeMap implements ExtensionToMimeTypeMap
'pgm' => 'image/x-portable-graymap',
'pgn' => 'application/x-chess-pgn',
'pgp' => 'application/pgp',
'phar' => 'application/octet-stream',
'php' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'php4' => 'application/x-httpd-php',

7
vendor/services.php vendored
View File

@ -1,9 +1,10 @@
<?php
// This file is automatically generated at:2022-04-17 07:13:49
// This file is automatically generated at:2022-04-18 13:52:33
declare (strict_types = 1);
return array (
0 => 'taoser\\addons\\Service',
1 => 'think\\captcha\\CaptchaService',
2 => 'think\\app\\Service',
3 => 'think\\trace\\Service',
2 => 'think\\migration\\Service',
3 => 'think\\app\\Service',
4 => 'think\\trace\\Service',
);

View File

@ -0,0 +1,3 @@
/vendor/
.idea
composer.lock

32
vendor/topthink/think-migration/LICENSE vendored Normal file
View File

@ -0,0 +1,32 @@
ThinkPHP遵循Apache2开源协议发布并提供免费使用。
版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
Apache Licence是著名的非盈利开源组织Apache采用的协议。
该协议和BSD类似鼓励代码共享和尊重原作者的著作权
允许代码修改,再作为开源或商业软件发布。需要满足
的条件:
1 需要给代码的用户一份Apache Licence
2 如果你修改了代码,需要在被修改的文件中说明;
3 在延伸的代码中(修改和有源代码衍生的代码中)需要
带有原来代码中的协议,商标,专利声明和其他原来作者规
定需要包含的说明;
4 如果再发布的产品中包含一个Notice文件则在Notice文
件中需要带有本协议内容。你可以在Notice中增加自己的
许可但不可以表现为对Apache Licence构成更改。
具体的协议参考http://www.apache.org/licenses/LICENSE-2.0
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,6 @@
# thinkphp6 数据库迁移工具
## 安装
~~~
composer require topthink/think-migration
~~~

View File

@ -0,0 +1,34 @@
{
"name": "topthink/think-migration",
"authors": [
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"license": "Apache-2.0",
"autoload": {
"psr-4": {
"Phinx\\": "phinx/src/Phinx",
"think\\migration\\": "src"
}
},
"extra": {
"think": {
"services": [
"think\\migration\\Service"
]
}
},
"require": {
"topthink/framework": "^6.0.0",
"topthink/think-helper": "^3.0.3"
},
"minimum-stability": "dev",
"suggest": {
"fzaninotto/faker": "Required to use the factory builder (^1.8)."
},
"require-dev": {
"fzaninotto/faker": "^1.8"
}
}

View File

@ -0,0 +1,370 @@
# Version History
**0.6.5** (Thursday, 27 October 2016)
* Documentation updates
* Pull requests
* [#831](https://github.com/robmorgan/phinx/pull/831) Typos
* [#929](https://github.com/robmorgan/phinx/pull/929) Support glob brace for seed paths
* [#949](https://github.com/robmorgan/phinx/pull/949) Fix for Config::getMigrationBaseClassName
* [#958](https://github.com/robmorgan/phinx/pull/958) Allow console input to be used within adapters
**0.6.4** (Wednesday, 27th July 2016)
* Documentation updates
* Pull requests
* [#909](https://github.com/robmorgan/phinx/pull/909) Declare test class properties
* [#910](https://github.com/robmorgan/phinx/pull/910), [#916](https://github.com/robmorgan/phinx/pull/916) Remove unused variables
* [#912](https://github.com/robmorgan/phinx/pull/912) ConfigInterface usage consistency
* [#914](https://github.com/robmorgan/phinx/pull/914) Set return values and @return documentation
* [#918](https://github.com/robmorgan/phinx/pull/918) Docblock correction for Phinx\Migration\Manager::executeSeed()
* [#921](https://github.com/robmorgan/phinx/pull/921) Add Phinx\Wrapper\TextWrapper::getSeed()
* Bug fixes
* [#908](https://github.com/robmorgan/phinx/pull/908) Fix setting options for Column, ForeignKey and Index
* [#922](https://github.com/robmorgan/phinx/pull/922) SQLite adapter drops table on changeColumn if there's a foreign key
**0.6.3** (Monday, 18th July 2016)
* New features
* [#707](https://github.com/robmorgan/phinx/pull/707/files) Add arguments for timestamps columns names
* Documentation cleanup
* Bug fixes
* [#884](https://github.com/robmorgan/phinx/pull/884) Only rollback 1 migration when only 2 migrations exist
* Input and Output are now correctly supplied to migration template creation classes
**0.6.2** (Thursday, 23rd June 2016)
* Fix breakpoint support for Postgres
* HHVM now passes all tests
**0.6.1** (Tuesday, 21st June 2016)
* Fix rollback when only 1 migration
**0.6.0** (Tuesday, 21st June 2016)
* Backward incompatibility - see [UPGRADE_0.6](UPGRADE_0.6.md) document
* Introduce Input and Output access to migrations and template creation
* New breakpoint command
* Moved version history to this CHANGELOG.md document
* More tests
**0.5.5** (Friday, 17th May 2016)
* Fix support for running multiple seeders
* Bug fix for migration template source - defaults and command line
* Bug fixes
**0.5.4** (Monday, 25th April 2016)
* Added support for running multiple seeders
* Use `GLOB_BRACE` when finding migrations only if its available
* Added support for MySQL `VARBINARY` column type
* Minor bug fixes
**0.5.3** (Monday, 7th March 2016)
* Critical fix: allow `migration_name` to be `null`. Introduced in 0.5.2
* Status command now shows migration start and end times
* Bug fix for rolling back by date
* Documentation improvements
**0.5.2** (Tuesday, 1st March 2016)
* Status command now includes missing migration names
* Added support for Postgres table comments
* Added `insert()` for the TablePrefixAdapter
* Fixed the migration verbosity flag
* Added MySQL 5.7 JSON support
* Added support for MySQL `FULLTEXT` indexes
* Postgres now supports `BIGSERIAL` for primary keys
* Added support for MySQL index limits
* Initial support for multiple migration paths (using glob)
* Documentation improvements
* Unit test enhancements
**0.5.1** (Wednesday, 30th December 2015)
* **PHP 5.3 is no longer supported!**
* Add support for Symfony 3.0 components
* Ensure that the `status` command returns the correct exit code
* Allow `$version` to be passed into templates
* Support for MySQL `YEAR` column type
* Multiple documentation updates and corrections
**0.5.0** (Monday, 30th November 2015)
* Support for seeding data after database creation
* The migration and seed directories are now nested under `db` by default
* Moved `Phinx\Migration\Util` to `Phinx\Util\Util`
* All `insert()` methods now have a slightly different method signature
* Fixed key/insert operations for MySQL
* Introduced `AdapterInterface::hasIndexByName()`
* Improved `dropForeignKey()` handling for SQLite
* Added support for the MySQL `binary` datatype. BLOBs now use the proper type.
* The status command shows a count of pending migrations in JSON output
* We are now testing against PHP 7
**0.4.6** (Friday, 11th September 2015)
* You can now set custom migration templates in the config files
* Support for MySQL unsigned booleans
* Support for Postgres `smallint` column types
* Support for `AFTER` when using `changeColumn()` with MySQL
* Support for `precision` and `scale` when using the Postgres `decimal` type
* Fixed a bug where duplicate migration names could be used
* The schema table is now created with a primary key
* Fixed issues when using the MySQL `STRICT_TRANS_TABLE` mode
* Improved the docs in the default migration template
* Made Box PHAR ignore the bundled `phinx.yml` configuration file
* Updated Box installer URL
* Internal code improvements
* Documentation improvements
**0.4.5** (Tuesday, 1st September 2015)
* The rollback command now supports a date argument
* Fixed DBLIB DSN strings for Microsoft SQL Server
* Postgres support for `jsonb` columns added
* The `addTimestamps()` helper method no longer updates the `created_at` column
* Fix for Postgres named foreign keys
* Unit test improvements (including strict warnings)
* Documentation improvements
**0.4.4** (Sunday, 14th June 2015)
* The `change` method is now the default
* Added a generic adapter insert method. Warning: The implementation will change!
* Updated Symfony depdencies to ~2.7
* Support for MySQL `BLOB` column types
* SQLite migration fixes
* Documentation improvements
**0.4.3** (Monday, 23rd Feburary 2015)
* Postgres bugfix for modifying column DEFAULTs
* MySQL bugfix for setting column INTEGER lengths
* SQLite bugfix for creating multiple indexes with similar names
**0.4.2.1** (Saturday, 7th Feburary 2015)
* Proper release, updated docs
**0.4.2** (Friday, 6th Feburary 2015)
* Postgres support for `json` columns added
* MySQL support for `enum` and `set` columns added
* Allow setting `identity` option on columns
* Template configuration and generation made more extensible
* Created a base class for `ProxyAdapter` and `TablePrefixAdapter`
* Switched to PSR-4
**0.4.1** (Tuesday, 23rd December 2014)
* MySQL support for reserved words in hasColumn and getColumns methods
* Better MySQL Adapter test coverage and performance fixes
* Updated dependent Symfony components to 2.6.x
**0.4.0** (Sunday, 14th December 2014)
* Adding initial support for running Phinx via a web interface
* Support for table prefixes and suffixes
* Bugfix for foreign key options
* MySQL keeps column default when renaming columns
* MySQL support for tiny/medium and longtext columns added
* Changed SQL Server binary columns to varbinary
* MySQL supports table comments
* Postgres supports column comments
* Empty strings are now supported for default column values
* Booleans are now supported for default column values
* Fixed SQL Server default constraint error when changing column types
* Migration timestamps are now created in UTC
* Locked Symfony Components to 2.5.0
* Support for custom migration base classes
* Cleaned up source code formatting
* Migrations have access to the output stream
* Support for custom PDO connections when a PHP config
* Added support for Postgres UUID type
* Fixed issue with Postgres dropping foreign keys
**0.3.8** (Sunday, 5th October 2014)
* Added new CHAR & Geospatial column types
* Added MySQL unix socket support
* Added precision & scale support for SQL Server
* Several bug fixes for SQLite
* Improved error messages
* Overall code optimizations
* Optimizations to MySQL hasTable method
**0.3.7** (Tuesday, 12th August 2014)
* Smarter configuration file support
* Support for Postgres Schemas
* Fixed charset support for Microsoft SQL Server
* Fix for Unique indexes in all adapters
* Improvements for MySQL foreign key migration syntax
* Allow MySQL column types with extra info
* Fixed SQLite autoincrement behaviour
* PHPDoc improvements
* Documentation improvements
* Unit test improvements
* Removing primary_key as a type
**0.3.6** (Sunday, 29th June 2014)
* Add custom adapter support
* Fix PHP 5.3 compatibility for SQL Server
**0.3.5** (Saturday, 21st June 2014)
* Added Microsoft SQL Server support
* Removed Primary Key column type
* Cleaned up and optimized many methods
* Updated Symfony dependencies to v2.5.0
* PHPDoc improvements
**0.3.4** (Sunday, 27th April 2014)
* Added support MySQL unsigned integer, biginteger, float and decimal types
* Added JSON output support for the status command
* Fix a bug where Postgres couldnt rollback foreign keys
* Moved Phinx type references to interface constants
* Fixed a bug with SQLite in-memory databases
**0.3.3** (Saturday, 22nd March 2014)
* Added support for JSON configuration
* Named index support for all adapters (thanks @archer308)
* Updated Composer dependencies
* Fix for SQLite Integer Type
* Fix for MySQL port option
**0.3.2** (Monday, 24th February 2014)
* Adding better Postgres type support
**0.3.1** (Sunday, 23rd February 2014)
* Adding MySQL charset support to the YAML config
* Removing trailing spaces
**0.3.0** (Sunday, 2nd February 2014)
* PSR-2 support
* Method to add timestamps easily to tables
* Support for column comments in the Postgres adapter
* Fixes for MySQL driver options
* Fixes for MySQL biginteger type
**0.2.9** (Saturday, 16th November 2013)
* Added SQLite Support
* Improving the unit tests, especially on Windows
**0.2.8** (Sunday, 25th August 2013)
* Added PostgresSQL Support
**0.2.7** (Saturday, 24th August 2013)
* Critical fix for a token parsing bug
* Removed legacy build system
* Improving docs
**0.2.6** (Saturday, 24th August 2013)
* Added support for environment vars in config files
* Added support for environment vars to set the Phinx Env
* Improving docs
* Fixed a bug with column names in indexes
* Changes for developers in regards to the unit tests
**0.2.5** (Sunday, 26th May 2013)
* Added support for Box Phar Archive Packaging
* Added support for MYSQL_ATTR driver options
* Fixed a bug where foreign keys cannot be removed
* Added support for MySQL table collation
* Updated Composer dependencies
* Removed verbosity options, now relies on Symfony instead
* Improved unit tests
**0.2.4** (Saturday, 20th April 2013)
* The Rollback command supports the verbosity parameter
* The Rollback command has more detailed output
* Table::dropForeignKey now returns the table instance
**0.2.3** (Saturday, 6th April 2013)
* Fixed a reporting bug when Phinx couldn't connect to a database
* Added support for the MySQL 'ON UPDATE' function
* Phinx timestamp is now mapped to MySQL timestamp instead of datetime
* Fixed a docs typo for the minimum PHP version
* Added UTF8 support for migrations
* Changed regex to handle migration names differently
* Added support for custom MySQL table engines such as MyISAM
* Added the change method to the migration template
**0.2.2** (Sunday, 3rd March 2013)
* Added a new verbosity parameter to see more output when migrating
* Support for PHP config files
**0.2.1** (Sunday, 3rd March 2013)
* Broken Release. Do not use!
* Unit tests no longer rely on the default phinx.yml file
* Running migrate for the first time does not give php warnings
* `default_migration_table` is now actually supported
* Updated docblocks to 2013.
**0.2.0** (Sunday, 13th January 2013)
* First Birthday Release
* Added Reversible Migrations
* Removed options parameter from AdapterInterface::hasColumn()
**0.1.7** (Tuesday, 8th January 2013)
* Improved documentation on the YAML configuration file
* Removed options parameter from AdapterInterface::dropIndex()
**0.1.6** (Sunday, 9th December 2012)
* Added foreign key support
* Removed PEAR support
* Support for auto_increment on custom id columns
* Bugfix for column default value 0
* Documentation improvements
**0.1.5** (Sunday, 4th November 2012)
* Added a test command
* Added transactions for adapters that support it
* Changing the Table API to use pending column methods
* Fixed a bug when defining multiple indexes on a table
**0.1.4** (Sunday, 21st October 2012)
* Documentation Improvements
**0.1.3** (Saturday, 20th October 2012)
* Fixed broken composer support
**0.1.2** (Saturday, 20th October 2012)
* Added composer support
* Now forces migrations to be in CamelCase format
* Now specifies the database name when migrating
* Creates the internal log table using its API instead of raw SQL
**0.1.1** (Wednesday, 13th June 2012)
* First point release. Ready for limited production use.
**0.1.0** (Friday, 13th January 2012)
* Initial public release.

View File

@ -0,0 +1,66 @@
# How to contribute to Phinx
Phinx relies heavily on external contributions in order to make it the best database migration
tool possible. Without the support of our 115+ contributors we wouldn't be where we are today!
We encourage anyone to submit documentation enhancements and code.
Issues, feature requests and bugs should be submitted using the Github issue tool:
https://github.com/robmorgan/phinx/issues.
This document briefly outlines the requirements to contribute code to Phinx.
## Considerations
Before you submit your pull request take a moment to answer the following questions.
Answering '**YES**' to all questions will increase the likelihood of your PR being accepted!
* Have I implemented my feature for as many database adapters as possible?
* Does my new feature improve Phinx's performance or keep it consistent?
* Does my feature fit within the database migration space?
* Is the code entirely my own and free from any commercial licensing?
* Am I happy to release my code under the MIT license?
* Is my code formatted using the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) coding standard?
**Note:** We accept bug fixes much faster into our development branch than features.
## Getting Started
Great, so you want to contribute. Let's get started:
1. Start by forking Phinx on GitHub: https://github.com/robmorgan/phinx
1. Clone your repository to a local directory on your development box.
1. If you do not have Composer set up already, install it:
```
curl -sS https://getcomposer.org/installer | php
```
1. Change to your Phinx clone directory and pull the necessary dependencies:
```
php composer.phar install
```
1. Copy the `phpunit.xml.dist` template to `phpunit.xml` and change the configuration to suit your environment. If you are not using any particular adapter you can disable it in the `phpunit.xml` file.
1. Run the unit tests locally to ensure they pass:
```
php vendor/bin/phpunit --config phpunit.xml
```
1. Write the code and unit tests for your bug fix or feature.
1. Add any relevant documentation.
1. Run the unit tests again and ensure they pass.
1. Open a pull request on the Github project page. Ensure the code is being merged into the latest development branch (e.g: `0.5.x-dev`) and not `master`.
## Documentation
The Phinx documentation is stored in the **docs** directory using the [RestructedText](http://docutils.sourceforge.net/rst.html) format. All documentation merged to `master` is automatically published to the Phinx documentation site available
at: http://docs.phinx.org. Keep this in mind when submitting your PR, or ask someone to merge the development branch back down to master.

View File

@ -0,0 +1,9 @@
(The MIT license)
Copyright (c) 2014 Rob Morgan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,128 @@
# [Phinx](https://phinx.org): Simple PHP Database Migrations
[![Build Status](https://travis-ci.org/robmorgan/phinx.png?branch=master)](https://travis-ci.org/robmorgan/phinx)
[![Build status](https://ci.appveyor.com/api/projects/status/9vag4892hfq6effr)](https://ci.appveyor.com/project/robmorgan/phinx)
[![Code Coverage](https://scrutinizer-ci.com/g/robmorgan/phinx/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/robmorgan/phinx/)
[![Latest Stable Version](https://poser.pugx.org/robmorgan/phinx/version.png)](https://packagist.org/packages/robmorgan/phinx)
[![Total Downloads](https://poser.pugx.org/robmorgan/phinx/d/total.png)](https://packagist.org/packages/robmorgan/phinx)
Phinx makes it ridiculously easy to manage the database migrations for your PHP app. In less than 5 minutes you can install Phinx and create your first database migration. Phinx is just about migrations without all the bloat of a database ORM system or framework.
**Check out http://docs.phinx.org for the comprehensive documentation.**
![phinxterm](https://cloud.githubusercontent.com/assets/178939/3887559/e6b5e524-21f2-11e4-8256-0ba6040725fc.gif)
### Features
* Write database migrations using database agnostic PHP code.
* Migrate up and down.
* Migrate on deployment.
* Seed data after database creation.
* Get going in less than 5 minutes.
* Stop worrying about the state of your database.
* Take advantage of SCM features such as branching.
* Integrate with any app.
### Supported Adapters
Phinx natively supports the following database adapters:
* MySQL
* PostgreSQL
* SQLite
* Microsoft SQL Server
## Install & Run
### Composer
The fastest way to install Phinx is to add it to your project using Composer (http://getcomposer.org/).
1. Install Composer:
```
curl -sS https://getcomposer.org/installer | php
```
1. Require Phinx as a dependency using Composer:
```
php composer.phar require robmorgan/phinx
```
1. Install Phinx:
```
php composer.phar install
```
1. Execute Phinx:
```
php vendor/bin/phinx
```
### As a Phar
You can also use the Box application to build Phinx as a Phar archive (https://box-project.github.io/box2/).
1. Clone Phinx from GitHub
```
git clone git://github.com/robmorgan/phinx.git
cd phinx
```
1. Install Composer
```
curl -s https://getcomposer.org/installer | php
```
1. Install the Phinx dependencies
```
php composer.phar install
```
1. Install Box:
```
curl -LSs https://box-project.github.io/box2/installer.php | php
```
1. Create a Phar archive
```
php box.phar build
```
## Documentation
Check out http://docs.phinx.org for the comprehensive documentation.
## Contributing
Please read the [CONTRIBUTING](CONTRIBUTING.md) document.
## News & Updates
Follow Rob (@\_rjm\_) on Twitter to stay up to date (http://twitter.com/_rjm_)
## Misc
### Version History
Please read the [CHANGELOG](CHANGELOG.md) document.
### License
(The MIT license)
Copyright (c) 2016 Rob Morgan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,181 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Db\Adapter;
/**
* Adapter factory and registry.
*
* Used for registering adapters and creating instances of adapters.
*
* @author Woody Gilk <woody.gilk@gmail.com>
*/
class AdapterFactory
{
/**
* @var AdapterFactory
*/
protected static $instance;
/**
* Get the factory singleton instance.
*
* @return AdapterFactory
*/
public static function instance()
{
if (!static::$instance) {
static::$instance = new static();
}
return static::$instance;
}
/**
* Class map of database adapters, indexed by PDO::ATTR_DRIVER_NAME.
*
* @var array
*/
protected $adapters = array(
'mysql' => 'Phinx\Db\Adapter\MysqlAdapter',
'pgsql' => 'Phinx\Db\Adapter\PostgresAdapter',
'sqlite' => 'Phinx\Db\Adapter\SQLiteAdapter',
'sqlsrv' => 'Phinx\Db\Adapter\SqlServerAdapter',
);
/**
* Class map of adapters wrappers, indexed by name.
*
* @var array
*/
protected $wrappers = array(
'prefix' => 'Phinx\Db\Adapter\TablePrefixAdapter',
'proxy' => 'Phinx\Db\Adapter\ProxyAdapter',
);
/**
* Add or replace an adapter with a fully qualified class name.
*
* @throws \RuntimeException
* @param string $name
* @param string $class
* @return $this
*/
public function registerAdapter($name, $class)
{
if (!is_subclass_of($class, 'Phinx\Db\Adapter\AdapterInterface')) {
throw new \RuntimeException(sprintf(
'Adapter class "%s" must implement Phinx\\Db\\Adapter\\AdapterInterface',
$class
));
}
$this->adapters[$name] = $class;
return $this;
}
/**
* Get an adapter class by name.
*
* @throws \RuntimeException
* @param string $name
* @return string
*/
protected function getClass($name)
{
if (empty($this->adapters[$name])) {
throw new \RuntimeException(sprintf(
'Adapter "%s" has not been registered',
$name
));
}
return $this->adapters[$name];
}
/**
* Get an adapter instance by name.
*
* @param string $name
* @param array $options
* @return AdapterInterface
*/
public function getAdapter($name, array $options)
{
$class = $this->getClass($name);
return new $class($options);
}
/**
* Add or replace a wrapper with a fully qualified class name.
*
* @throws \RuntimeException
* @param string $name
* @param string $class
* @return $this
*/
public function registerWrapper($name, $class)
{
if (!is_subclass_of($class, 'Phinx\Db\Adapter\WrapperInterface')) {
throw new \RuntimeException(sprintf(
'Wrapper class "%s" must be implement Phinx\\Db\\Adapter\\WrapperInterface',
$class
));
}
$this->wrappers[$name] = $class;
return $this;
}
/**
* Get a wrapper class by name.
*
* @throws \RuntimeException
* @param string $name
* @return string
*/
protected function getWrapperClass($name)
{
if (empty($this->wrappers[$name])) {
throw new \RuntimeException(sprintf(
'Wrapper "%s" has not been registered',
$name
));
}
return $this->wrappers[$name];
}
/**
* Get a wrapper instance by name.
*
* @param string $name
* @param AdapterInterface $adapter
* @return AdapterInterface
*/
public function getWrapper($name, AdapterInterface $adapter)
{
$class = $this->getWrapperClass($name);
return new $class($adapter);
}
}

View File

@ -0,0 +1,510 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db\Adapter
*/
namespace Phinx\Db\Adapter;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
use Phinx\Db\Table;
use Phinx\Db\Table\Column;
use Phinx\Db\Table\Index;
use Phinx\Db\Table\ForeignKey;
use Phinx\Migration\MigrationInterface;
/**
* Adapter Interface.
*
* @author Rob Morgan <robbym@gmail.com>
*/
interface AdapterInterface
{
const PHINX_TYPE_STRING = 'string';
const PHINX_TYPE_CHAR = 'char';
const PHINX_TYPE_TEXT = 'text';
const PHINX_TYPE_INTEGER = 'integer';
const PHINX_TYPE_BIG_INTEGER = 'biginteger';
const PHINX_TYPE_FLOAT = 'float';
const PHINX_TYPE_DECIMAL = 'decimal';
const PHINX_TYPE_DATETIME = 'datetime';
const PHINX_TYPE_TIMESTAMP = 'timestamp';
const PHINX_TYPE_TIME = 'time';
const PHINX_TYPE_DATE = 'date';
const PHINX_TYPE_BINARY = 'binary';
const PHINX_TYPE_VARBINARY = 'varbinary';
const PHINX_TYPE_BLOB = 'blob';
const PHINX_TYPE_BOOLEAN = 'boolean';
const PHINX_TYPE_JSON = 'json';
const PHINX_TYPE_JSONB = 'jsonb';
const PHINX_TYPE_UUID = 'uuid';
const PHINX_TYPE_FILESTREAM = 'filestream';
// Geospatial database types
const PHINX_TYPE_GEOMETRY = 'geometry';
const PHINX_TYPE_POINT = 'point';
const PHINX_TYPE_LINESTRING = 'linestring';
const PHINX_TYPE_POLYGON = 'polygon';
// only for mysql so far
const PHINX_TYPE_ENUM = 'enum';
const PHINX_TYPE_SET = 'set';
/**
* Get all migrated version numbers.
*
* @return array
*/
public function getVersions();
/**
* Get all migration log entries, indexed by version number.
*
* @return array
*/
public function getVersionLog();
/**
* Set adapter configuration options.
*
* @param array $options
* @return AdapterInterface
*/
public function setOptions(array $options);
/**
* Get all adapter options.
*
* @return array
*/
public function getOptions();
/**
* Check if an option has been set.
*
* @param string $name
* @return boolean
*/
public function hasOption($name);
/**
* Get a single adapter option, or null if the option does not exist.
*
* @param string $name
* @return mixed
*/
public function getOption($name);
/**
* Sets the console input.
*
* @param InputInterface $input Input
* @return AdapterInterface
*/
public function setInput(InputInterface $input);
/**
* Gets the console input.
*
* @return InputInterface
*/
public function getInput();
/**
* Sets the console output.
*
* @param OutputInterface $output Output
* @return AdapterInterface
*/
public function setOutput(OutputInterface $output);
/**
* Gets the console output.
*
* @return OutputInterface
*/
public function getOutput();
/**
* Records a migration being run.
*
* @param MigrationInterface $migration Migration
* @param string $direction Direction
* @param int $startTime Start Time
* @param int $endTime End Time
* @return AdapterInterface
*/
public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime);
/**
* Toggle a migration breakpoint.
*
* @param MigrationInterface $migration
*
* @return AdapterInterface
*/
public function toggleBreakpoint(MigrationInterface $migration);
/**
* Reset all migration breakpoints.
*
* @return int The number of breakpoints reset
*/
public function resetAllBreakpoints();
/**
* Does the schema table exist?
*
* @deprecated use hasTable instead.
* @return boolean
*/
public function hasSchemaTable();
/**
* Creates the schema table.
*
* @return void
*/
public function createSchemaTable();
/**
* Returns the adapter type.
*
* @return string
*/
public function getAdapterType();
/**
* Initializes the database connection.
*
* @throws \RuntimeException When the requested database driver is not installed.
* @return void
*/
public function connect();
/**
* Closes the database connection.
*
* @return void
*/
public function disconnect();
/**
* Does the adapter support transactions?
*
* @return boolean
*/
public function hasTransactions();
/**
* Begin a transaction.
*
* @return void
*/
public function beginTransaction();
/**
* Commit a transaction.
*
* @return void
*/
public function commitTransaction();
/**
* Rollback a transaction.
*
* @return void
*/
public function rollbackTransaction();
/**
* Executes a SQL statement and returns the number of affected rows.
*
* @param string $sql SQL
* @return int
*/
public function execute($sql);
/**
* Executes a SQL statement and returns the result as an array.
*
* @param string $sql SQL
* @return array
*/
public function query($sql);
/**
* Executes a query and returns only one row as an array.
*
* @param string $sql SQL
* @return array
*/
public function fetchRow($sql);
/**
* Executes a query and returns an array of rows.
*
* @param string $sql SQL
* @return array
*/
public function fetchAll($sql);
/**
* Inserts data into a table.
*
* @param Table $table where to insert data
* @param array $row
* @return void
*/
public function insert(Table $table, $row);
/**
* Quotes a table name for use in a query.
*
* @param string $tableName Table Name
* @return string
*/
public function quoteTableName($tableName);
/**
* Quotes a column name for use in a query.
*
* @param string $columnName Table Name
* @return string
*/
public function quoteColumnName($columnName);
/**
* Checks to see if a table exists.
*
* @param string $tableName Table Name
* @return boolean
*/
public function hasTable($tableName);
/**
* Creates the specified database table.
*
* @param Table $table Table
* @return void
*/
public function createTable(Table $table);
/**
* Renames the specified database table.
*
* @param string $tableName Table Name
* @param string $newName New Name
* @return void
*/
public function renameTable($tableName, $newName);
/**
* Drops the specified database table.
*
* @param string $tableName Table Name
* @return void
*/
public function dropTable($tableName);
/**
* Returns table columns
*
* @param string $tableName Table Name
* @return Column[]
*/
public function getColumns($tableName);
/**
* Checks to see if a column exists.
*
* @param string $tableName Table Name
* @param string $columnName Column Name
* @return boolean
*/
public function hasColumn($tableName, $columnName);
/**
* Adds the specified column to a database table.
*
* @param Table $table Table
* @param Column $column Column
* @return void
*/
public function addColumn(Table $table, Column $column);
/**
* Renames the specified column.
*
* @param string $tableName Table Name
* @param string $columnName Column Name
* @param string $newColumnName New Column Name
* @return void
*/
public function renameColumn($tableName, $columnName, $newColumnName);
/**
* Change a table column type.
*
* @param string $tableName Table Name
* @param string $columnName Column Name
* @param Column $newColumn New Column
* @return Table
*/
public function changeColumn($tableName, $columnName, Column $newColumn);
/**
* Drops the specified column.
*
* @param string $tableName Table Name
* @param string $columnName Column Name
* @return void
*/
public function dropColumn($tableName, $columnName);
/**
* Checks to see if an index exists.
*
* @param string $tableName Table Name
* @param mixed $columns Column(s)
* @return boolean
*/
public function hasIndex($tableName, $columns);
/**
* Checks to see if an index specified by name exists.
*
* @param string $tableName Table Name
* @param string $indexName
* @return boolean
*/
public function hasIndexByName($tableName, $indexName);
/**
* Adds the specified index to a database table.
*
* @param Table $table Table
* @param Index $index Index
* @return void
*/
public function addIndex(Table $table, Index $index);
/**
* Drops the specified index from a database table.
*
* @param string $tableName
* @param mixed $columns Column(s)
* @return void
*/
public function dropIndex($tableName, $columns);
/**
* Drops the index specified by name from a database table.
*
* @param string $tableName
* @param string $indexName
* @return void
*/
public function dropIndexByName($tableName, $indexName);
/**
* Checks to see if a foreign key exists.
*
* @param string $tableName
* @param string[] $columns Column(s)
* @param string $constraint Constraint name
* @return boolean
*/
public function hasForeignKey($tableName, $columns, $constraint = null);
/**
* Adds the specified foreign key to a database table.
*
* @param Table $table
* @param ForeignKey $foreignKey
* @return void
*/
public function addForeignKey(Table $table, ForeignKey $foreignKey);
/**
* Drops the specified foreign key from a database table.
*
* @param string $tableName
* @param string[] $columns Column(s)
* @param string $constraint Constraint name
* @return void
*/
public function dropForeignKey($tableName, $columns, $constraint = null);
/**
* Returns an array of the supported Phinx column types.
*
* @return array
*/
public function getColumnTypes();
/**
* Checks that the given column is of a supported type.
*
* @param Column $column
* @return boolean
*/
public function isValidColumnType(Column $column);
/**
* Converts the Phinx logical type to the adapter's SQL type.
*
* @param string $type
* @param integer $limit
* @return string
*/
public function getSqlType($type, $limit = null);
/**
* Creates a new database.
*
* @param string $name Database Name
* @param array $options Options
* @return void
*/
public function createDatabase($name, $options = array());
/**
* Checks to see if a database exists.
*
* @param string $name Database Name
* @return boolean
*/
public function hasDatabase($name);
/**
* Drops the specified database.
*
* @param string $name Database Name
* @return void
*/
public function dropDatabase($name);
}

View File

@ -0,0 +1,507 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db\Adapter
*/
namespace Phinx\Db\Adapter;
use Phinx\Db\Table;
use Phinx\Db\Table\Column;
use Phinx\Db\Table\Index;
use Phinx\Db\Table\ForeignKey;
use Phinx\Migration\MigrationInterface;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Adapter Wrapper.
*
* Proxy commands through to another adapter, allowing modification of
* parameters during calls.
*
* @author Woody Gilk <woody.gilk@gmail.com>
*/
abstract class AdapterWrapper implements AdapterInterface, WrapperInterface
{
/**
* @var AdapterInterface
*/
protected $adapter;
/**
* {@inheritdoc}
*/
public function __construct(AdapterInterface $adapter)
{
$this->setAdapter($adapter);
}
/**
* {@inheritdoc}
*/
public function setAdapter(AdapterInterface $adapter)
{
$this->adapter = $adapter;
return $this;
}
/**
* {@inheritdoc}
*/
public function getAdapter()
{
return $this->adapter;
}
/**
* {@inheritdoc}
*/
public function setOptions(array $options)
{
$this->adapter->setOptions($options);
return $this;
}
/**
* {@inheritdoc}
*/
public function getOptions()
{
return $this->adapter->getOptions();
}
/**
* {@inheritdoc}
*/
public function hasOption($name)
{
return $this->adapter->hasOption($name);
}
/**
* {@inheritdoc}
*/
public function getOption($name)
{
return $this->adapter->getOption($name);
}
/**
* {@inheritdoc}
*/
public function setInput(InputInterface $input)
{
$this->adapter->setInput($input);
return $this;
}
/**
* {@inheritdoc}
*/
public function getInput()
{
return $this->adapter->getInput();
}
/**
* {@inheritdoc}
*/
public function setOutput(OutputInterface $output)
{
$this->adapter->setOutput($output);
return $this;
}
/**
* {@inheritdoc}
*/
public function getOutput()
{
return $this->adapter->getOutput();
}
/**
* {@inheritdoc}
*/
public function connect()
{
return $this->getAdapter()->connect();
}
/**
* {@inheritdoc}
*/
public function disconnect()
{
return $this->getAdapter()->disconnect();
}
/**
* {@inheritdoc}
*/
public function execute($sql)
{
return $this->getAdapter()->execute($sql);
}
/**
* {@inheritdoc}
*/
public function query($sql)
{
return $this->getAdapter()->query($sql);
}
/**
* {@inheritdoc}
*/
public function insert(Table $table, $row)
{
return $this->getAdapter()->insert($table, $row);
}
/**
* {@inheritdoc}
*/
public function fetchRow($sql)
{
return $this->getAdapter()->fetchRow($sql);
}
/**
* {@inheritdoc}
*/
public function fetchAll($sql)
{
return $this->getAdapter()->fetchAll($sql);
}
/**
* {@inheritdoc}
*/
public function getVersions()
{
return $this->getAdapter()->getVersions();
}
/**
* {@inheritdoc}
*/
public function getVersionLog()
{
return $this->getAdapter()->getVersionLog();
}
/**
* {@inheritdoc}
*/
public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime)
{
$this->getAdapter()->migrated($migration, $direction, $startTime, $endTime);
return $this;
}
/**
* @inheritDoc
*/
public function toggleBreakpoint(MigrationInterface $migration)
{
$this->getAdapter()->toggleBreakpoint($migration);
return $this;
}
/**
* @inheritDoc
*/
public function resetAllBreakpoints()
{
return $this->getAdapter()->resetAllBreakpoints();
}
/**
* {@inheritdoc}
*/
public function hasSchemaTable()
{
return $this->getAdapter()->hasSchemaTable();
}
/**
* {@inheritdoc}
*/
public function createSchemaTable()
{
return $this->getAdapter()->createSchemaTable();
}
/**
* {@inheritdoc}
*/
public function getColumnTypes()
{
return $this->getAdapter()->getColumnTypes();
}
/**
* {@inheritdoc}
*/
public function isValidColumnType(Column $column)
{
return $this->getAdapter()->isValidColumnType($column);
}
/**
* {@inheritdoc}
*/
public function hasTransactions()
{
return $this->getAdapter()->hasTransactions();
}
/**
* {@inheritdoc}
*/
public function beginTransaction()
{
return $this->getAdapter()->beginTransaction();
}
/**
* {@inheritdoc}
*/
public function commitTransaction()
{
return $this->getAdapter()->commitTransaction();
}
/**
* {@inheritdoc}
*/
public function rollbackTransaction()
{
return $this->getAdapter()->rollbackTransaction();
}
/**
* {@inheritdoc}
*/
public function quoteTableName($tableName)
{
return $this->getAdapter()->quoteTableName($tableName);
}
/**
* {@inheritdoc}
*/
public function quoteColumnName($columnName)
{
return $this->getAdapter()->quoteColumnName($columnName);
}
/**
* {@inheritdoc}
*/
public function hasTable($tableName)
{
return $this->getAdapter()->hasTable($tableName);
}
/**
* {@inheritdoc}
*/
public function createTable(Table $table)
{
return $this->getAdapter()->createTable($table);
}
/**
* {@inheritdoc}
*/
public function renameTable($tableName, $newTableName)
{
return $this->getAdapter()->renameTable($tableName, $newTableName);
}
/**
* {@inheritdoc}
*/
public function dropTable($tableName)
{
return $this->getAdapter()->dropTable($tableName);
}
/**
* {@inheritdoc}
*/
public function getColumns($tableName)
{
return $this->getAdapter()->getColumns($tableName);
}
/**
* {@inheritdoc}
*/
public function hasColumn($tableName, $columnName)
{
return $this->getAdapter()->hasColumn($tableName, $columnName);
}
/**
* {@inheritdoc}
*/
public function addColumn(Table $table, Column $column)
{
return $this->getAdapter()->addColumn($table, $column);
}
/**
* {@inheritdoc}
*/
public function renameColumn($tableName, $columnName, $newColumnName)
{
return $this->getAdapter()->renameColumn($tableName, $columnName, $newColumnName);
}
/**
* {@inheritdoc}
*/
public function changeColumn($tableName, $columnName, Column $newColumn)
{
return $this->getAdapter()->changeColumn($tableName, $columnName, $newColumn);
}
/**
* {@inheritdoc}
*/
public function dropColumn($tableName, $columnName)
{
return $this->getAdapter()->dropColumn($tableName, $columnName);
}
/**
* {@inheritdoc}
*/
public function hasIndex($tableName, $columns)
{
return $this->getAdapter()->hasIndex($tableName, $columns);
}
/**
* {@inheritdoc}
*/
public function hasIndexByName($tableName, $indexName)
{
return $this->getAdapter()->hasIndexByName($tableName, $indexName);
}
/**
* {@inheritdoc}
*/
public function addIndex(Table $table, Index $index)
{
return $this->getAdapter()->addIndex($table, $index);
}
/**
* {@inheritdoc}
*/
public function dropIndex($tableName, $columns, $options = array())
{
return $this->getAdapter()->dropIndex($tableName, $columns, $options);
}
/**
* {@inheritdoc}
*/
public function dropIndexByName($tableName, $indexName)
{
return $this->getAdapter()->dropIndexByName($tableName, $indexName);
}
/**
* {@inheritdoc}
*/
public function hasForeignKey($tableName, $columns, $constraint = null)
{
return $this->getAdapter()->hasForeignKey($tableName, $columns, $constraint);
}
/**
* {@inheritdoc}
*/
public function addForeignKey(Table $table, ForeignKey $foreignKey)
{
return $this->getAdapter()->addForeignKey($table, $foreignKey);
}
/**
* {@inheritdoc}
*/
public function dropForeignKey($tableName, $columns, $constraint = null)
{
return $this->getAdapter()->dropForeignKey($tableName, $columns, $constraint);
}
/**
* {@inheritdoc}
*/
public function getSqlType($type, $limit = null)
{
return $this->getAdapter()->getSqlType($type, $limit);
}
/**
* {@inheritdoc}
*/
public function createDatabase($name, $options = array())
{
return $this->getAdapter()->createDatabase($name, $options);
}
/**
* {@inheritdoc}
*/
public function hasDatabase($name)
{
return $this->getAdapter()->hasDatabase($name);
}
/**
* {@inheritdoc}
*/
public function dropDatabase($name)
{
return $this->getAdapter()->dropDatabase($name);
}
/**
* @inheritDoc
*/
public function castToBool($value)
{
return $this->getAdapter()->castToBool($value);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,587 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db\Adapter
*/
namespace Phinx\Db\Adapter;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
use Phinx\Db\Table;
use Phinx\Db\Table\Column;
use Phinx\Migration\MigrationInterface;
/**
* Phinx PDO Adapter.
*
* @author Rob Morgan <robbym@gmail.com>
*/
abstract class PdoAdapter implements AdapterInterface
{
/**
* @var array
*/
protected $options = array();
/**
* @var InputInterface
*/
protected $input;
/**
* @var OutputInterface
*/
protected $output;
/**
* @var string
*/
protected $schemaTableName = 'migrations';
/**
* @var \PDO
*/
protected $connection;
/**
* @var float
*/
protected $commandStartTime;
/**
* Class Constructor.
*
* @param array $options Options
* @param InputInterface $input Input Interface
* @param OutputInterface $output Output Interface
*/
public function __construct(array $options, InputInterface $input = null, OutputInterface $output = null)
{
$this->setOptions($options);
if (null !== $input) {
$this->setInput($input);
}
if (null !== $output) {
$this->setOutput($output);
}
}
/**
* {@inheritdoc}
*/
public function setOptions(array $options)
{
$this->options = $options;
if (isset($options['default_migration_table'])) {
$this->setSchemaTableName($options['default_migration_table']);
}
if (isset($options['connection'])) {
$this->setConnection($options['connection']);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function getOptions()
{
return $this->options;
}
/**
* {@inheritdoc}
*/
public function hasOption($name)
{
return isset($this->options[$name]);
}
/**
* {@inheritdoc}
*/
public function getOption($name)
{
if (!$this->hasOption($name)) {
return;
}
return $this->options[$name];
}
/**
* {@inheritdoc}
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
return $this;
}
/**
* {@inheritdoc}
*/
public function getInput()
{
return $this->input;
}
/**
* {@inheritdoc}
*/
public function setOutput(OutputInterface $output)
{
$this->output = $output;
return $this;
}
/**
* {@inheritdoc}
*/
public function getOutput()
{
if (null === $this->output) {
$output = new OutputInterface('nothing');
$this->setOutput($output);
}
return $this->output;
}
/**
* Sets the schema table name.
*
* @param string $schemaTableName Schema Table Name
* @return PdoAdapter
*/
public function setSchemaTableName($schemaTableName)
{
$this->schemaTableName = $schemaTableName;
return $this;
}
/**
* Gets the schema table name.
*
* @return string
*/
public function getSchemaTableName()
{
return $this->schemaTableName;
}
/**
* Sets the database connection.
*
* @param \PDO $connection Connection
* @return AdapterInterface
*/
public function setConnection(\PDO $connection)
{
$this->connection = $connection;
// Create the schema table if it doesn't already exist
if (!$this->hasSchemaTable()) {
$this->createSchemaTable();
} else {
$table = new Table($this->getSchemaTableName(), array(), $this);
if (!$table->hasColumn('migration_name')) {
$table
->addColumn('migration_name', 'string',
array('limit' => 100, 'after' => 'version', 'default' => null, 'null' => true)
)
->save();
}
if (!$table->hasColumn('breakpoint')) {
$table
->addColumn('breakpoint', 'boolean', array('default' => false))
->save();
}
}
return $this;
}
/**
* Gets the database connection
*
* @return \PDO
*/
public function getConnection()
{
if (null === $this->connection) {
$this->connect();
}
return $this->connection;
}
/**
* Sets the command start time
*
* @param int $time
* @return AdapterInterface
*/
public function setCommandStartTime($time)
{
$this->commandStartTime = $time;
return $this;
}
/**
* Gets the command start time
*
* @return int
*/
public function getCommandStartTime()
{
return $this->commandStartTime;
}
/**
* Start timing a command.
*
* @return void
*/
public function startCommandTimer()
{
$this->setCommandStartTime(microtime(true));
}
/**
* Stop timing the current command and write the elapsed time to the
* output.
*
* @return void
*/
public function endCommandTimer()
{
$end = microtime(true);
if (OutputInterface::VERBOSITY_VERBOSE <= $this->getOutput()->getVerbosity()) {
$this->getOutput()->writeln(' -> ' . sprintf('%.4fs', $end - $this->getCommandStartTime()));
}
}
/**
* Write a Phinx command to the output.
*
* @param string $command Command Name
* @param array $args Command Args
* @return void
*/
public function writeCommand($command, $args = array())
{
if (OutputInterface::VERBOSITY_VERBOSE <= $this->getOutput()->getVerbosity()) {
if (count($args)) {
$outArr = array();
foreach ($args as $arg) {
if (is_array($arg)) {
$arg = array_map(function ($value) {
return '\'' . $value . '\'';
}, $arg);
$outArr[] = '[' . implode(', ', $arg) . ']';
continue;
}
$outArr[] = '\'' . $arg . '\'';
}
$this->getOutput()->writeln(' -- ' . $command . '(' . implode(', ', $outArr) . ')');
return;
}
$this->getOutput()->writeln(' -- ' . $command);
}
}
/**
* {@inheritdoc}
*/
public function connect()
{
}
/**
* {@inheritdoc}
*/
public function disconnect()
{
}
/**
* {@inheritdoc}
*/
public function execute($sql)
{
return $this->getConnection()->exec($sql);
}
/**
* {@inheritdoc}
*/
public function query($sql)
{
return $this->getConnection()->query($sql);
}
/**
* {@inheritdoc}
*/
public function fetchRow($sql)
{
$result = $this->query($sql);
return $result->fetch();
}
/**
* {@inheritdoc}
*/
public function fetchAll($sql)
{
$rows = array();
$result = $this->query($sql);
while ($row = $result->fetch()) {
$rows[] = $row;
}
return $rows;
}
/**
* {@inheritdoc}
*/
public function insert(Table $table, $row)
{
$this->startCommandTimer();
$this->writeCommand('insert', array($table->getName()));
$sql = sprintf(
"INSERT INTO %s ",
$this->quoteTableName($table->getName())
);
$columns = array_keys($row);
$sql .= "(". implode(', ', array_map(array($this, 'quoteColumnName'), $columns)) . ")";
$sql .= " VALUES (" . implode(', ', array_fill(0, count($columns), '?')) . ")";
$stmt = $this->getConnection()->prepare($sql);
$stmt->execute(array_values($row));
$this->endCommandTimer();
}
/**
* {@inheritdoc}
*/
public function getVersions()
{
$rows = $this->getVersionLog();
return array_keys($rows);
}
/**
* {@inheritdoc}
*/
public function getVersionLog()
{
$result = array();
$rows = $this->fetchAll(sprintf('SELECT * FROM %s ORDER BY version ASC', $this->getSchemaTableName()));
foreach ($rows as $version) {
$result[$version['version']] = $version;
}
return $result;
}
/**
* {@inheritdoc}
*/
public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime)
{
if (strcasecmp($direction, MigrationInterface::UP) === 0) {
// up
$sql = sprintf(
"INSERT INTO %s (%s, %s, %s, %s, %s) VALUES ('%s', '%s', '%s', '%s', %s);",
$this->getSchemaTableName(),
$this->quoteColumnName('version'),
$this->quoteColumnName('migration_name'),
$this->quoteColumnName('start_time'),
$this->quoteColumnName('end_time'),
$this->quoteColumnName('breakpoint'),
$migration->getVersion(),
substr($migration->getName(), 0, 100),
$startTime,
$endTime,
$this->castToBool(false)
);
$this->query($sql);
} else {
// down
$sql = sprintf(
"DELETE FROM %s WHERE %s = '%s'",
$this->getSchemaTableName(),
$this->quoteColumnName('version'),
$migration->getVersion()
);
$this->query($sql);
}
return $this;
}
/**
* @inheritDoc
*/
public function toggleBreakpoint(MigrationInterface $migration)
{
$this->query(
sprintf(
'UPDATE %1$s SET %2$s = CASE %2$s WHEN %3$s THEN %4$s ELSE %3$s END WHERE %5$s = \'%6$s\';',
$this->getSchemaTableName(),
$this->quoteColumnName('breakpoint'),
$this->castToBool(true),
$this->castToBool(false),
$this->quoteColumnName('version'),
$migration->getVersion()
)
);
return $this;
}
/**
* @inheritDoc
*/
public function resetAllBreakpoints()
{
return $this->execute(
sprintf(
'UPDATE %1$s SET %2$s = %3$s WHERE %2$s <> %3$s;',
$this->getSchemaTableName(),
$this->quoteColumnName('breakpoint'),
$this->castToBool(false)
)
);
}
/**
* {@inheritdoc}
*/
public function hasSchemaTable()
{
return $this->hasTable($this->getSchemaTableName());
}
/**
* {@inheritdoc}
*/
public function createSchemaTable()
{
try {
$options = array(
'id' => false,
'primary_key' => 'version'
);
$table = new Table($this->getSchemaTableName(), $options, $this);
if ($this->getConnection()->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'mysql'
&& version_compare($this->getConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.6.0', '>=')) {
$table->addColumn('version', 'biginteger', array('limit' => 14))
->addColumn('migration_name', 'string', array('limit' => 100, 'default' => null, 'null' => true))
->addColumn('start_time', 'timestamp', array('default' => 'CURRENT_TIMESTAMP'))
->addColumn('end_time', 'timestamp', array('default' => 'CURRENT_TIMESTAMP'))
->addColumn('breakpoint', 'boolean', array('default' => false))
->save();
} else {
$table->addColumn('version', 'biginteger')
->addColumn('migration_name', 'string', array('limit' => 100, 'default' => null, 'null' => true))
->addColumn('start_time', 'timestamp')
->addColumn('end_time', 'timestamp')
->addColumn('breakpoint', 'boolean', array('default' => false))
->save();
}
} catch (\Exception $exception) {
throw new \InvalidArgumentException('There was a problem creating the schema table: ' . $exception->getMessage());
}
}
/**
* {@inheritdoc}
*/
public function getAdapterType()
{
return $this->getOption('adapter');
}
/**
* {@inheritdoc}
*/
public function getColumnTypes()
{
return array(
'string',
'char',
'text',
'integer',
'biginteger',
'float',
'decimal',
'datetime',
'timestamp',
'time',
'date',
'blob',
'binary',
'varbinary',
'boolean',
'uuid',
// Geospatial data types
'geometry',
'point',
'linestring',
'polygon',
);
}
/**
* {@inheritdoc}
*/
public function isValidColumnType(Column $column) {
return in_array($column->getType(), $this->getColumnTypes());
}
/**
* Cast a value to a boolean appropriate for the adapter.
*
* @param mixed $value The value to be cast
*
* @return mixed
*/
public function castToBool($value)
{
return (bool) $value ? 1 : 0;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,325 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db\Adapter
*/
namespace Phinx\Db\Adapter;
use Phinx\Db\Table;
use Phinx\Db\Table\Column;
use Phinx\Db\Table\Index;
use Phinx\Db\Table\ForeignKey;
use Phinx\Migration\IrreversibleMigrationException;
/**
* Phinx Proxy Adapter.
*
* Used for recording migration commands to automatically reverse them.
*
* @author Rob Morgan <robbym@gmail.com>
*/
class ProxyAdapter extends AdapterWrapper
{
/**
* @var array
*/
protected $commands;
/**
* {@inheritdoc}
*/
public function getAdapterType()
{
return 'ProxyAdapter';
}
/**
* {@inheritdoc}
*/
public function createTable(Table $table)
{
$this->recordCommand('createTable', array($table->getName()));
}
/**
* {@inheritdoc}
*/
public function renameTable($tableName, $newTableName)
{
$this->recordCommand('renameTable', array($tableName, $newTableName));
}
/**
* {@inheritdoc}
*/
public function dropTable($tableName)
{
$this->recordCommand('dropTable', array($tableName));
}
/**
* {@inheritdoc}
*/
public function addColumn(Table $table, Column $column)
{
$this->recordCommand('addColumn', array($table, $column));
}
/**
* {@inheritdoc}
*/
public function renameColumn($tableName, $columnName, $newColumnName)
{
$this->recordCommand('renameColumn', array($tableName, $columnName, $newColumnName));
}
/**
* {@inheritdoc}
*/
public function changeColumn($tableName, $columnName, Column $newColumn)
{
$this->recordCommand('changeColumn', array($tableName, $columnName, $newColumn));
}
/**
* {@inheritdoc}
*/
public function dropColumn($tableName, $columnName)
{
$this->recordCommand('dropColumn', array($tableName, $columnName));
}
/**
* {@inheritdoc}
*/
public function addIndex(Table $table, Index $index)
{
$this->recordCommand('addIndex', array($table, $index));
}
/**
* {@inheritdoc}
*/
public function dropIndex($tableName, $columns, $options = array())
{
$this->recordCommand('dropIndex', array($tableName, $columns, $options));
}
/**
* {@inheritdoc}
*/
public function dropIndexByName($tableName, $indexName)
{
$this->recordCommand('dropIndexByName', array($tableName, $indexName));
}
/**
* {@inheritdoc}
*/
public function addForeignKey(Table $table, ForeignKey $foreignKey)
{
$this->recordCommand('addForeignKey', array($table, $foreignKey));
}
/**
* {@inheritdoc}
*/
public function dropForeignKey($tableName, $columns, $constraint = null)
{
$this->recordCommand('dropForeignKey', array($columns, $constraint));
}
/**
* {@inheritdoc}
*/
public function createDatabase($name, $options = array())
{
$this->recordCommand('createDatabase', array($name, $options));
}
/**
* Record a command for execution later.
*
* @param string $name Command Name
* @param array $arguments Command Arguments
* @return void
*/
public function recordCommand($name, $arguments)
{
$this->commands[] = array(
'name' => $name,
'arguments' => $arguments
);
}
/**
* Sets an array of recorded commands.
*
* @param array $commands Commands
* @return ProxyAdapter
*/
public function setCommands($commands)
{
$this->commands = $commands;
return $this;
}
/**
* Gets an array of the recorded commands.
*
* @return array
*/
public function getCommands()
{
return $this->commands;
}
/**
* Gets an array of the recorded commands in reverse.
*
* @throws IrreversibleMigrationException if a command cannot be reversed.
* @return array
*/
public function getInvertedCommands()
{
if (null === $this->getCommands()) {
return array();
}
$invCommands = array();
$supportedCommands = array(
'createTable', 'renameTable', 'addColumn',
'renameColumn', 'addIndex', 'addForeignKey'
);
foreach (array_reverse($this->getCommands()) as $command) {
if (!in_array($command['name'], $supportedCommands)) {
throw new IrreversibleMigrationException(sprintf(
'Cannot reverse a "%s" command',
$command['name']
));
}
$invertMethod = 'invert' . ucfirst($command['name']);
$invertedCommand = $this->$invertMethod($command['arguments']);
$invCommands[] = array(
'name' => $invertedCommand['name'],
'arguments' => $invertedCommand['arguments']
);
}
return $invCommands;
}
/**
* Execute the recorded commands.
*
* @return void
*/
public function executeCommands()
{
$commands = $this->getCommands();
foreach ($commands as $command) {
call_user_func_array(array($this->getAdapter(), $command['name']), $command['arguments']);
}
}
/**
* Execute the recorded commands in reverse.
*
* @return void
*/
public function executeInvertedCommands()
{
$commands = $this->getInvertedCommands();
foreach ($commands as $command) {
call_user_func_array(array($this->getAdapter(), $command['name']), $command['arguments']);
}
}
/**
* Returns the reverse of a createTable command.
*
* @param array $args Method Arguments
* @return array
*/
public function invertCreateTable($args)
{
return array('name' => 'dropTable', 'arguments' => array($args[0]));
}
/**
* Returns the reverse of a renameTable command.
*
* @param array $args Method Arguments
* @return array
*/
public function invertRenameTable($args)
{
return array('name' => 'renameTable', 'arguments' => array($args[1], $args[0]));
}
/**
* Returns the reverse of a addColumn command.
*
* @param array $args Method Arguments
* @return array
*/
public function invertAddColumn($args)
{
return array('name' => 'dropColumn', 'arguments' => array($args[0]->getName(), $args[1]->getName()));
}
/**
* Returns the reverse of a renameColumn command.
*
* @param array $args Method Arguments
* @return array
*/
public function invertRenameColumn($args)
{
return array('name' => 'renameColumn', 'arguments' => array($args[0], $args[2], $args[1]));
}
/**
* Returns the reverse of a addIndex command.
*
* @param array $args Method Arguments
* @return array
*/
public function invertAddIndex($args)
{
return array('name' => 'dropIndex', 'arguments' => array($args[0]->getName(), $args[1]->getColumns()));
}
/**
* Returns the reverse of a addForeignKey command.
*
* @param array $args Method Arguments
* @return array
*/
public function invertAddForeignKey($args)
{
return array('name' => 'dropForeignKey', 'arguments' => array($args[0]->getName(), $args[1]->getColumns()));
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,272 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db\Adapter
*/
namespace Phinx\Db\Adapter;
use Phinx\Db\Table;
use Phinx\Db\Table\Column;
use Phinx\Db\Table\Index;
use Phinx\Db\Table\ForeignKey;
/**
* Table prefix/suffix adapter.
*
* Used for inserting a prefix or suffix into table names.
*
* @author Samuel Fisher <sam@sfisher.co>
*/
class TablePrefixAdapter extends AdapterWrapper
{
/**
* {@inheritdoc}
*/
public function getAdapterType()
{
return 'TablePrefixAdapter';
}
/**
* {@inheritdoc}
*/
public function hasTable($tableName)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::hasTable($adapterTableName);
}
/**
* {@inheritdoc}
*/
public function createTable(Table $table)
{
$adapterTable = clone $table;
$adapterTableName = $this->getAdapterTableName($table->getName());
$adapterTable->setName($adapterTableName);
foreach ($adapterTable->getForeignKeys() as $fk) {
$adapterReferenceTable = $fk->getReferencedTable();
$adapterReferenceTableName = $this->getAdapterTableName($adapterReferenceTable->getName());
$adapterReferenceTable->setName($adapterReferenceTableName);
}
return parent::createTable($adapterTable);
}
/**
* {@inheritdoc}
*/
public function renameTable($tableName, $newTableName)
{
$adapterTableName = $this->getAdapterTableName($tableName);
$adapterNewTableName = $this->getAdapterTableName($newTableName);
return parent::renameTable($adapterTableName, $adapterNewTableName);
}
/**
* {@inheritdoc}
*/
public function dropTable($tableName)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::dropTable($adapterTableName);
}
/**
* {@inheritdoc}
*/
public function getColumns($tableName)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::getColumns($adapterTableName);
}
/**
* {@inheritdoc}
*/
public function hasColumn($tableName, $columnName)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::hasColumn($adapterTableName, $columnName);
}
/**
* {@inheritdoc}
*/
public function addColumn(Table $table, Column $column)
{
$adapterTable = clone $table;
$adapterTableName = $this->getAdapterTableName($table->getName());
$adapterTable->setName($adapterTableName);
return parent::addColumn($adapterTable, $column);
}
/**
* {@inheritdoc}
*/
public function renameColumn($tableName, $columnName, $newColumnName)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::renameColumn($adapterTableName, $columnName, $newColumnName);
}
/**
* {@inheritdoc}
*/
public function changeColumn($tableName, $columnName, Column $newColumn)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::changeColumn($adapterTableName, $columnName, $newColumn);
}
/**
* {@inheritdoc}
*/
public function dropColumn($tableName, $columnName)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::dropColumn($adapterTableName, $columnName);
}
/**
* {@inheritdoc}
*/
public function hasIndex($tableName, $columns)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::hasIndex($adapterTableName, $columns);
}
/**
* {@inheritdoc}
*/
public function hasIndexByName($tableName, $indexName)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::hasIndexByName($adapterTableName, $indexName);
}
/**
* {@inheritdoc}
*/
public function addIndex(Table $table, Index $index)
{
$adapterTable = clone $table;
$adapterTableName = $this->getAdapterTableName($table->getName());
$adapterTable->setName($adapterTableName);
return parent::addIndex($adapterTable, $index);
}
/**
* {@inheritdoc}
*/
public function dropIndex($tableName, $columns, $options = array())
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::dropIndex($adapterTableName, $columns, $options);
}
/**
* {@inheritdoc}
*/
public function dropIndexByName($tableName, $indexName)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::dropIndexByName($adapterTableName, $indexName);
}
/**
* {@inheritdoc}
*/
public function hasForeignKey($tableName, $columns, $constraint = null)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::hasForeignKey($adapterTableName, $columns, $constraint);
}
/**
* {@inheritdoc}
*/
public function addForeignKey(Table $table, ForeignKey $foreignKey)
{
$adapterTable = clone $table;
$adapterTableName = $this->getAdapterTableName($table->getName());
$adapterTable->setName($adapterTableName);
return parent::addForeignKey($adapterTable, $foreignKey);
}
/**
* {@inheritdoc}
*/
public function dropForeignKey($tableName, $columns, $constraint = null)
{
$adapterTableName = $this->getAdapterTableName($tableName);
return parent::dropForeignKey($adapterTableName, $columns, $constraint);
}
/**
* {@inheritdoc}
*/
public function insert(Table $table, $row)
{
$adapterTable = clone $table;
$adapterTableName = $this->getAdapterTableName($table->getName());
$adapterTable->setName($adapterTableName);
return parent::insert($adapterTable, $row);
}
/**
* Gets the table prefix.
*
* @return string
*/
public function getPrefix()
{
return (string) $this->getOption('table_prefix');
}
/**
* Gets the table suffix.
*
* @return string
*/
public function getSuffix()
{
return (string) $this->getOption('table_suffix');
}
/**
* Applies the prefix and suffix to the table name.
*
* @param string $tableName
* @return string
*/
public function getAdapterTableName($tableName)
{
return $this->getPrefix() . $tableName . $this->getSuffix();
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db\Adapter
*/
namespace Phinx\Db\Adapter;
/**
* Wrapper Interface.
*
* @author Woody Gilk <woody.gilk@gmail.com>
*/
interface WrapperInterface
{
/**
* Class constructor, must always wrap another adapter.
*
* @param AdapterInterface $adapter
*/
public function __construct(AdapterInterface $adapter);
/**
* Sets the database adapter to proxy commands to.
*
* @param AdapterInterface $adapter
* @return AdapterInterface
*/
public function setAdapter(AdapterInterface $adapter);
/**
* Gets the database adapter.
*
* @throws \RuntimeException if the adapter has not been set
* @return AdapterInterface
*/
public function getAdapter();
}

View File

@ -0,0 +1,674 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db
*/
namespace Phinx\Db;
use Phinx\Db\Table\Column;
use Phinx\Db\Table\Index;
use Phinx\Db\Table\ForeignKey;
use Phinx\Db\Adapter\AdapterInterface;
/**
*
* This object is based loosely on: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html.
*/
class Table
{
/**
* @var string
*/
protected $name;
/**
* @var array
*/
protected $options = array();
/**
* @var AdapterInterface
*/
protected $adapter;
/**
* @var array
*/
protected $columns = array();
/**
* @var array
*/
protected $indexes = array();
/**
* @var ForeignKey[]
*/
protected $foreignKeys = array();
/**
* @var array
*/
protected $data = array();
/**
* Class Constuctor.
*
* @param string $name Table Name
* @param array $options Options
* @param AdapterInterface $adapter Database Adapter
*/
public function __construct($name, $options = array(), AdapterInterface $adapter = null)
{
$this->setName($name);
$this->setOptions($options);
if (null !== $adapter) {
$this->setAdapter($adapter);
}
}
/**
* Sets the table name.
*
* @param string $name Table Name
* @return Table
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Gets the table name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Sets the table options.
*
* @param array $options
* @return Table
*/
public function setOptions($options)
{
$this->options = $options;
return $this;
}
/**
* Gets the table options.
*
* @return array
*/
public function getOptions()
{
return $this->options;
}
/**
* Sets the database adapter.
*
* @param AdapterInterface $adapter Database Adapter
* @return Table
*/
public function setAdapter(AdapterInterface $adapter)
{
$this->adapter = $adapter;
return $this;
}
/**
* Gets the database adapter.
*
* @return AdapterInterface
*/
public function getAdapter()
{
return $this->adapter;
}
/**
* Does the table exist?
*
* @return boolean
*/
public function exists()
{
return $this->getAdapter()->hasTable($this->getName());
}
/**
* Drops the database table.
*
* @return void
*/
public function drop()
{
$this->getAdapter()->dropTable($this->getName());
}
/**
* Renames the database table.
*
* @param string $newTableName New Table Name
* @return Table
*/
public function rename($newTableName)
{
$this->getAdapter()->renameTable($this->getName(), $newTableName);
$this->setName($newTableName);
return $this;
}
/**
* Sets an array of columns waiting to be committed.
* Use setPendingColumns
*
* @deprecated
* @param array $columns Columns
* @return Table
*/
public function setColumns($columns)
{
$this->setPendingColumns($columns);
}
/**
* Gets an array of the table columns.
*
* @return Column[]
*/
public function getColumns()
{
return $this->getAdapter()->getColumns($this->getName());
}
/**
* Sets an array of columns waiting to be committed.
*
* @param array $columns Columns
* @return Table
*/
public function setPendingColumns($columns)
{
$this->columns = $columns;
return $this;
}
/**
* Gets an array of columns waiting to be committed.
*
* @return Column[]
*/
public function getPendingColumns()
{
return $this->columns;
}
/**
* Sets an array of columns waiting to be indexed.
*
* @param array $indexes Indexes
* @return Table
*/
public function setIndexes($indexes)
{
$this->indexes = $indexes;
return $this;
}
/**
* Gets an array of indexes waiting to be committed.
*
* @return array
*/
public function getIndexes()
{
return $this->indexes;
}
/**
* Sets an array of foreign keys waiting to be commited.
*
* @param ForeignKey[] $foreignKeys foreign keys
* @return Table
*/
public function setForeignKeys($foreignKeys)
{
$this->foreignKeys = $foreignKeys;
return $this;
}
/**
* Gets an array of foreign keys waiting to be commited.
*
* @return array|ForeignKey[]
*/
public function getForeignKeys()
{
return $this->foreignKeys;
}
/**
* Sets an array of data to be inserted.
*
* @param array $data Data
* @return Table
*/
public function setData($data)
{
$this->data = $data;
return $this;
}
/**
* Gets the data waiting to be inserted.
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* Resets all of the pending table changes.
*
* @return void
*/
public function reset()
{
$this->setPendingColumns(array());
$this->setIndexes(array());
$this->setForeignKeys(array());
$this->setData(array());
}
/**
* Add a table column.
*
* Type can be: string, text, integer, float, decimal, datetime, timestamp,
* time, date, binary, boolean.
*
* Valid options can be: limit, default, null, precision or scale.
*
* @param string|Column $columnName Column Name
* @param string $type Column Type
* @param array $options Column Options
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @return Table
*/
public function addColumn($columnName, $type = null, $options = array())
{
// we need an adapter set to add a column
if (null === $this->getAdapter()) {
throw new \RuntimeException('An adapter must be specified to add a column.');
}
// create a new column object if only strings were supplied
if (!$columnName instanceof Column) {
$column = new Column();
$column->setName($columnName);
$column->setType($type);
$column->setOptions($options); // map options to column methods
} else {
$column = $columnName;
}
// Delegate to Adapters to check column type
if (!$this->getAdapter()->isValidColumnType($column)) {
throw new \InvalidArgumentException(sprintf(
'An invalid column type "%s" was specified for column "%s".',
$column->getType(),
$column->getName()
));
}
$this->columns[] = $column;
return $this;
}
/**
* Remove a table column.
*
* @param string $columnName Column Name
* @return Table
*/
public function removeColumn($columnName)
{
$this->getAdapter()->dropColumn($this->getName(), $columnName);
return $this;
}
/**
* Rename a table column.
*
* @param string $oldName Old Column Name
* @param string $newName New Column Name
* @return Table
*/
public function renameColumn($oldName, $newName)
{
$this->getAdapter()->renameColumn($this->getName(), $oldName, $newName);
return $this;
}
/**
* Change a table column type.
*
* @param string $columnName Column Name
* @param string|Column $newColumnType New Column Type
* @param array $options Options
* @return Table
*/
public function changeColumn($columnName, $newColumnType, $options = array())
{
// create a column object if one wasn't supplied
if (!$newColumnType instanceof Column) {
$newColumn = new Column();
$newColumn->setType($newColumnType);
$newColumn->setOptions($options);
} else {
$newColumn = $newColumnType;
}
// if the name was omitted use the existing column name
if (null === $newColumn->getName() || strlen($newColumn->getName()) === 0) {
$newColumn->setName($columnName);
}
$this->getAdapter()->changeColumn($this->getName(), $columnName, $newColumn);
return $this;
}
/**
* Checks to see if a column exists.
*
* @param string $columnName Column Name
* @param array $options Options
* @return boolean
*/
public function hasColumn($columnName, $options = array())
{
return $this->getAdapter()->hasColumn($this->getName(), $columnName, $options);
}
/**
* Add an index to a database table.
*
* In $options you can specific unique = true/false or name (index name).
*
* @param string|array|Index $columns Table Column(s)
* @param array $options Index Options
* @return Table
*/
public function addIndex($columns, $options = array())
{
// create a new index object if strings or an array of strings were supplied
if (!$columns instanceof Index) {
$index = new Index();
if (is_string($columns)) {
$columns = array($columns); // str to array
}
$index->setColumns($columns);
$index->setOptions($options);
} else {
$index = $columns;
}
$this->indexes[] = $index;
return $this;
}
/**
* Removes the given index from a table.
*
* @param array $columns Columns
* @param array $options Options
* @return Table
*/
public function removeIndex($columns, $options = array())
{
$this->getAdapter()->dropIndex($this->getName(), $columns, $options);
return $this;
}
/**
* Removes the given index identified by its name from a table.
*
* @param string $name Index name
* @return Table
*/
public function removeIndexByName($name)
{
$this->getAdapter()->dropIndexByName($this->getName(), $name);
return $this;
}
/**
* Checks to see if an index exists.
*
* @param string|array $columns Columns
* @param array $options Options
* @return boolean
*/
public function hasIndex($columns, $options = array())
{
return $this->getAdapter()->hasIndex($this->getName(), $columns, $options);
}
/**
* Add a foreign key to a database table.
*
* In $options you can specify on_delete|on_delete = cascade|no_action ..,
* on_update, constraint = constraint name.
*
* @param string|array $columns Columns
* @param string|Table $referencedTable Referenced Table
* @param string|array $referencedColumns Referenced Columns
* @param array $options Options
* @return Table
*/
public function addForeignKey($columns, $referencedTable, $referencedColumns = array('id'), $options = array())
{
if (is_string($referencedColumns)) {
$referencedColumns = array($referencedColumns); // str to array
}
$fk = new ForeignKey();
if ($referencedTable instanceof Table) {
$fk->setReferencedTable($referencedTable);
} else {
$fk->setReferencedTable(new Table($referencedTable, array(), $this->adapter));
}
$fk->setColumns($columns)
->setReferencedColumns($referencedColumns)
->setOptions($options);
$this->foreignKeys[] = $fk;
return $this;
}
/**
* Removes the given foreign key from the table.
*
* @param string|array $columns Column(s)
* @param null|string $constraint Constraint names
* @return Table
*/
public function dropForeignKey($columns, $constraint = null)
{
if (is_string($columns)) {
$columns = array($columns);
}
if ($constraint) {
$this->getAdapter()->dropForeignKey($this->getName(), array(), $constraint);
} else {
$this->getAdapter()->dropForeignKey($this->getName(), $columns);
}
return $this;
}
/**
* Checks to see if a foreign key exists.
*
* @param string|array $columns Column(s)
* @param null|string $constraint Constraint names
* @return boolean
*/
public function hasForeignKey($columns, $constraint = null)
{
return $this->getAdapter()->hasForeignKey($this->getName(), $columns, $constraint);
}
/**
* Add timestamp columns created_at and updated_at to the table.
*
* @param string $createdAtColumnName
* @param string $updatedAtColumnName
*
* @return Table
*/
public function addTimestamps($createdAtColumnName = 'created_at', $updatedAtColumnName = 'updated_at')
{
$createdAtColumnName = is_null($createdAtColumnName) ? 'created_at' : $createdAtColumnName;
$updatedAtColumnName = is_null($updatedAtColumnName) ? 'updated_at' : $updatedAtColumnName;
$this->addColumn($createdAtColumnName, 'timestamp', array(
'default' => 'CURRENT_TIMESTAMP',
'update' => ''
))
->addColumn($updatedAtColumnName, 'timestamp', array(
'null' => true,
'default' => null
));
return $this;
}
/**
* Insert data into the table.
*
* @param $data array of data in the form:
* array(
* array("col1" => "value1", "col2" => "anotherValue1"),
* array("col2" => "value2", "col2" => "anotherValue2"),
* )
* or array("col1" => "value1", "col2" => "anotherValue1")
*
* @return Table
*/
public function insert($data)
{
// handle array of array situations
if (isset($data[0]) && is_array($data[0])) {
foreach ($data as $row) {
$this->data[] = $row;
}
return $this;
}
$this->data[] = $data;
return $this;
}
/**
* Creates a table from the object instance.
*
* @return void
*/
public function create()
{
$this->getAdapter()->createTable($this);
$this->saveData();
$this->reset(); // reset pending changes
}
/**
* Updates a table from the object instance.
*
* @throws \RuntimeException
* @return void
*/
public function update()
{
if (!$this->exists()) {
throw new \RuntimeException('Cannot update a table that doesn\'t exist!');
}
// update table
foreach ($this->getPendingColumns() as $column) {
$this->getAdapter()->addColumn($this, $column);
}
foreach ($this->getIndexes() as $index) {
$this->getAdapter()->addIndex($this, $index);
}
foreach ($this->getForeignKeys() as $foreignKey) {
$this->getAdapter()->addForeignKey($this, $foreignKey);
}
$this->saveData();
$this->reset(); // reset pending changes
}
/**
* Commit the pending data waiting for insertion.
*
* @return void
*/
public function saveData()
{
foreach ($this->getData() as $row) {
$this->getAdapter()->insert($this, $row);
}
}
/**
* Commits the table changes.
*
* If the table doesn't exist it is created otherwise it is updated.
*
* @return void
*/
public function save()
{
if ($this->exists()) {
$this->update(); // update the table
} else {
$this->create(); // create the table
}
$this->reset(); // reset pending changes
}
}

View File

@ -0,0 +1,550 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db
*/
namespace Phinx\Db\Table;
/**
*
* This object is based loosely on: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html.
*/
class Column
{
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $type;
/**
* @var integer
*/
protected $limit = null;
/**
* @var boolean
*/
protected $null = false;
/**
* @var mixed
*/
protected $default = null;
/**
* @var boolean
*/
protected $identity = false;
/**
* @var integer
*/
protected $precision;
/**
* @var integer
*/
protected $scale;
/**
* @var string
*/
protected $after;
/**
* @var string
*/
protected $update;
/**
* @var string
*/
protected $comment;
/**
* @var boolean
*/
protected $signed = true;
/**
* @var boolean
*/
protected $timezone = false;
/**
* @var array
*/
protected $properties = array();
/**
* @var array
*/
protected $values;
/**
* Sets the column name.
*
* @param string $name
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Gets the column name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Sets the column type.
*
* @param string $type
* @return $this
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Gets the column type.
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Sets the column limit.
*
* @param integer $limit
* @return $this
*/
public function setLimit($limit)
{
$this->limit = $limit;
return $this;
}
/**
* Gets the column limit.
*
* @return integer
*/
public function getLimit()
{
return $this->limit;
}
/**
* Sets whether the column allows nulls.
*
* @param boolean $null
* @return $this
*/
public function setNull($null)
{
$this->null = (bool) $null;
return $this;
}
/**
* Gets whether the column allows nulls.
*
* @return boolean
*/
public function getNull()
{
return $this->null;
}
/**
* Does the column allow nulls?
*
* @return boolean
*/
public function isNull()
{
return $this->getNull();
}
/**
* Sets the default column value.
*
* @param mixed $default
* @return $this
*/
public function setDefault($default)
{
$this->default = $default;
return $this;
}
/**
* Gets the default column value.
*
* @return mixed
*/
public function getDefault()
{
return $this->default;
}
/**
* Sets whether or not the column is an identity column.
*
* @param boolean $identity
* @return $this
*/
public function setIdentity($identity)
{
$this->identity = $identity;
return $this;
}
/**
* Gets whether or not the column is an identity column.
*
* @return boolean
*/
public function getIdentity()
{
return $this->identity;
}
/**
* Is the column an identity column?
*
* @return boolean
*/
public function isIdentity()
{
return $this->getIdentity();
}
/**
* Sets the name of the column to add this column after.
*
* @param string $after After
* @return $this
*/
public function setAfter($after)
{
$this->after = $after;
return $this;
}
/**
* Returns the name of the column to add this column after.
*
* @return string
*/
public function getAfter()
{
return $this->after;
}
/**
* Sets the 'ON UPDATE' mysql column function.
*
* @param string $update On Update function
* @return $this
*/
public function setUpdate($update)
{
$this->update = $update;
return $this;
}
/**
* Returns the value of the ON UPDATE column function.
*
* @return string
*/
public function getUpdate()
{
return $this->update;
}
/**
* Sets the column precision for decimal.
*
* @param integer $precision
* @return $this
*/
public function setPrecision($precision)
{
$this->precision = $precision;
return $this;
}
/**
* Gets the column precision for decimal.
*
* @return integer
*/
public function getPrecision()
{
return $this->precision;
}
/**
* Sets the column scale for decimal.
*
* @param integer $scale
* @return $this
*/
public function setScale($scale)
{
$this->scale = $scale;
return $this;
}
/**
* Gets the column scale for decimal.
*
* @return integer
*/
public function getScale()
{
return $this->scale;
}
/**
* Sets the column comment.
*
* @param string $comment
* @return $this
*/
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
/**
* Gets the column comment.
*
* @return string
*/
public function getComment()
{
return $this->comment;
}
/**
* Sets whether field should be signed.
*
* @param bool $signed
* @return $this
*/
public function setSigned($signed)
{
$this->signed = (bool) $signed;
return $this;
}
/**
* Gets whether field should be signed.
*
* @return string
*/
public function getSigned()
{
return $this->signed;
}
/**
* Should the column be signed?
*
* @return boolean
*/
public function isSigned()
{
return $this->getSigned();
}
/**
* Sets whether the field should have a timezone identifier.
* Used for date/time columns only!
*
* @param bool $timezone
* @return $this
*/
public function setTimezone($timezone)
{
$this->timezone = (bool) $timezone;
return $this;
}
/**
* Gets whether field has a timezone identifier.
*
* @return boolean
*/
public function getTimezone()
{
return $this->timezone;
}
/**
* Should the column have a timezone?
*
* @return boolean
*/
public function isTimezone()
{
return $this->getTimezone();
}
/**
* Sets field properties.
*
* @param array $properties
*
* @return $this
*/
public function setProperties($properties)
{
$this->properties = $properties;
return $this;
}
/**
* Gets field properties
*
* @return array
*/
public function getProperties()
{
return $this->properties;
}
/**
* Sets field values.
*
* @param mixed (array|string) $values
*
* @return $this
*/
public function setValues($values)
{
if (!is_array($values)) {
$values = preg_split('/,\s*/', $values);
}
$this->values = $values;
return $this;
}
/**
* Gets field values
*
* @return string
*/
public function getValues()
{
return $this->values;
}
/**
* Gets all allowed options. Each option must have a corresponding `setFoo` method.
*
* @return array
*/
protected function getValidOptions()
{
return array(
'limit',
'default',
'null',
'identity',
'precision',
'scale',
'after',
'update',
'comment',
'signed',
'timezone',
'properties',
'values',
);
}
/**
* Gets all aliased options. Each alias must reference a valid option.
*
* @return array
*/
protected function getAliasedOptions()
{
return array(
'length' => 'limit',
);
}
/**
* Utility method that maps an array of column options to this objects methods.
*
* @param array $options Options
* @return $this
*/
public function setOptions($options)
{
$validOptions = $this->getValidOptions();
$aliasOptions = $this->getAliasedOptions();
foreach ($options as $option => $value) {
if (isset($aliasOptions[$option])) {
// proxy alias -> option
$option = $aliasOptions[$option];
}
if (!in_array($option, $validOptions, true)) {
throw new \RuntimeException(sprintf('"%s" is not a valid column option.', $option));
}
$method = 'set' . ucfirst($option);
$this->$method($value);
}
return $this;
}
}

View File

@ -0,0 +1,252 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db
* @author Leonid Kuzmin <lndkuzmin@gmail.com>
*/
namespace Phinx\Db\Table;
use Phinx\Db\Table;
class ForeignKey
{
const CASCADE = 'CASCADE';
const RESTRICT = 'RESTRICT';
const SET_NULL = 'SET NULL';
const NO_ACTION = 'NO ACTION';
/**
* @var array
*/
protected $columns = array();
/**
* @var Table
*/
protected $referencedTable;
/**
* @var array
*/
protected $referencedColumns = array();
/**
* @var string
*/
protected $onDelete;
/**
* @var string
*/
protected $onUpdate;
/**
* @var string|boolean
*/
protected $constraint;
/**
* Sets the foreign key columns.
*
* @param array|string $columns
* @return ForeignKey
*/
public function setColumns($columns)
{
if (is_string($columns)) {
$columns = array($columns);
}
$this->columns = $columns;
return $this;
}
/**
* Gets the foreign key columns.
*
* @return array
*/
public function getColumns()
{
return $this->columns;
}
/**
* Sets the foreign key referenced table.
*
* @param Table $table
* @return ForeignKey
*/
public function setReferencedTable(Table $table)
{
$this->referencedTable = $table;
return $this;
}
/**
* Gets the foreign key referenced table.
*
* @return Table
*/
public function getReferencedTable()
{
return $this->referencedTable;
}
/**
* Sets the foreign key referenced columns.
*
* @param array $referencedColumns
* @return ForeignKey
*/
public function setReferencedColumns(array $referencedColumns)
{
$this->referencedColumns = $referencedColumns;
return $this;
}
/**
* Gets the foreign key referenced columns.
*
* @return array
*/
public function getReferencedColumns()
{
return $this->referencedColumns;
}
/**
* Sets ON DELETE action for the foreign key.
*
* @param string $onDelete
* @return ForeignKey
*/
public function setOnDelete($onDelete)
{
$this->onDelete = $this->normalizeAction($onDelete);
return $this;
}
/**
* Gets ON DELETE action for the foreign key.
*
* @return string
*/
public function getOnDelete()
{
return $this->onDelete;
}
/**
* Gets ON UPDATE action for the foreign key.
*
* @return string
*/
public function getOnUpdate()
{
return $this->onUpdate;
}
/**
* Sets ON UPDATE action for the foreign key.
*
* @param string $onUpdate
* @return ForeignKey
*/
public function setOnUpdate($onUpdate)
{
$this->onUpdate = $this->normalizeAction($onUpdate);
return $this;
}
/**
* Sets constraint for the foreign key.
*
* @param string $constraint
* @return ForeignKey
*/
public function setConstraint($constraint)
{
$this->constraint = $constraint;
return $this;
}
/**
* Gets constraint name for the foreign key.
*
* @return string
*/
public function getConstraint()
{
return $this->constraint;
}
/**
* Utility method that maps an array of index options to this objects methods.
*
* @param array $options Options
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @return ForeignKey
*/
public function setOptions($options)
{
// Valid Options
$validOptions = array('delete', 'update', 'constraint');
foreach ($options as $option => $value) {
if (!in_array($option, $validOptions, true)) {
throw new \RuntimeException(sprintf('"%s" is not a valid foreign key option.', $option));
}
// handle $options['delete'] as $options['update']
if ('delete' === $option) {
$this->setOnDelete($value);
} elseif ('update' === $option) {
$this->setOnUpdate($value);
} else {
$method = 'set' . ucfirst($option);
$this->$method($value);
}
}
return $this;
}
/**
* From passed value checks if it's correct and fixes if needed
*
* @param string $action
* @throws \InvalidArgumentException
* @return string
*/
protected function normalizeAction($action)
{
$constantName = 'static::' . str_replace(' ', '_', strtoupper(trim($action)));
if (!defined($constantName)) {
throw new \InvalidArgumentException('Unknown action passed: ' . $action);
}
return constant($constantName);
}
}

View File

@ -0,0 +1,185 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Db
*/
namespace Phinx\Db\Table;
class Index
{
/**
* @var string
*/
const UNIQUE = 'unique';
/**
* @var string
*/
const INDEX = 'index';
/**
* @var string
*/
const FULLTEXT = 'fulltext';
/**
* @var array
*/
protected $columns;
/**
* @var string
*/
protected $type = self::INDEX;
/**
* @var string
*/
protected $name = null;
/**
* @var integer
*/
protected $limit = null;
/**
* Sets the index columns.
*
* @param array $columns
* @return Index
*/
public function setColumns($columns)
{
$this->columns = $columns;
return $this;
}
/**
* Gets the index columns.
*
* @return array
*/
public function getColumns()
{
return $this->columns;
}
/**
* Sets the index type.
*
* @param string $type
* @return Index
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Gets the index type.
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Sets the index name.
*
* @param string $name
* @return Index
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Gets the index name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Sets the index limit.
*
* @param integer $limit
* @return Index
*/
public function setLimit($limit)
{
$this->limit = $limit;
return $this;
}
/**
* Gets the index limit.
*
* @return integer
*/
public function getLimit()
{
return $this->limit;
}
/**
* Utility method that maps an array of index options to this objects methods.
*
* @param array $options Options
* @throws \RuntimeException
* @return Index
*/
public function setOptions($options)
{
// Valid Options
$validOptions = array('type', 'unique', 'name', 'limit');
foreach ($options as $option => $value) {
if (!in_array($option, $validOptions, true)) {
throw new \RuntimeException(sprintf('"%s" is not a valid index option.', $option));
}
// handle $options['unique']
if (strcasecmp($option, self::UNIQUE) === 0) {
if ((bool) $value) {
$this->setType(self::UNIQUE);
}
continue;
}
$method = 'set' . ucfirst($option);
$this->$method($value);
}
return $this;
}
}

View File

@ -0,0 +1,273 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
use Phinx\Db\Table;
use Phinx\Db\Adapter\AdapterInterface;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Abstract Migration Class.
*
* It is expected that the migrations you write extend from this class.
*
* This abstract class proxies the various database methods to your specified
* adapter.
*
* @author Rob Morgan <robbym@gmail.com>
*/
abstract class AbstractMigration implements MigrationInterface
{
/**
* @var float
*/
protected $version;
/**
* @var AdapterInterface
*/
protected $adapter;
/**
* @var OutputInterface
*/
protected $output;
/**
* @var InputInterface
*/
protected $input;
/**
* Class Constructor.
*
* @param int $version Migration Version
* @param InputInterface|null $input
* @param OutputInterface|null $output
*/
final public function __construct($version, InputInterface $input = null, OutputInterface $output = null)
{
$this->version = $version;
if (!is_null($input)){
$this->setInput($input);
}
if (!is_null($output)){
$this->setOutput($output);
}
$this->init();
}
/**
* Initialize method.
*
* @return void
*/
protected function init()
{
}
/**
* {@inheritdoc}
*/
public function up()
{
}
/**
* {@inheritdoc}
*/
public function down()
{
}
/**
* {@inheritdoc}
*/
public function setAdapter(AdapterInterface $adapter)
{
$this->adapter = $adapter;
return $this;
}
/**
* {@inheritdoc}
*/
public function getAdapter()
{
return $this->adapter;
}
/**
* {@inheritdoc}
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
return $this;
}
/**
* {@inheritdoc}
*/
public function getInput()
{
return $this->input;
}
/**
* {@inheritdoc}
*/
public function setOutput(OutputInterface $output)
{
$this->output = $output;
return $this;
}
/**
* {@inheritdoc}
*/
public function getOutput()
{
return $this->output;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return get_class($this);
}
/**
* {@inheritdoc}
*/
public function setVersion($version)
{
$this->version = $version;
return $this;
}
/**
* {@inheritdoc}
*/
public function getVersion()
{
return $this->version;
}
/**
* {@inheritdoc}
*/
public function execute($sql)
{
return $this->getAdapter()->execute($sql);
}
/**
* {@inheritdoc}
*/
public function query($sql)
{
return $this->getAdapter()->query($sql);
}
/**
* {@inheritdoc}
*/
public function fetchRow($sql)
{
return $this->getAdapter()->fetchRow($sql);
}
/**
* {@inheritdoc}
*/
public function fetchAll($sql)
{
return $this->getAdapter()->fetchAll($sql);
}
/**
* {@inheritdoc}
*/
public function insert($table, $data)
{
// convert to table object
if (is_string($table)) {
$table = new Table($table, array(), $this->getAdapter());
}
return $table->insert($data)->save();
}
/**
* {@inheritdoc}
*/
public function createDatabase($name, $options)
{
$this->getAdapter()->createDatabase($name, $options);
}
/**
* {@inheritdoc}
*/
public function dropDatabase($name)
{
$this->getAdapter()->dropDatabase($name);
}
/**
* {@inheritdoc}
*/
public function hasTable($tableName)
{
return $this->getAdapter()->hasTable($tableName);
}
/**
* {@inheritdoc}
*/
public function table($tableName, $options = array())
{
return new Table($tableName, $options, $this->getAdapter());
}
/**
* A short-hand method to drop the given database table.
*
* @param string $tableName Table Name
* @return void
*/
public function dropTable($tableName)
{
$this->table($tableName)->drop();
}
}

View File

@ -0,0 +1,97 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
abstract class AbstractTemplateCreation implements CreationInterface
{
/**
* @var InputInterface
*/
protected $input;
/**
* @var OutputInterface
*/
protected $output;
/**
* Class Constructor.
*
* @param InputInterface|null $input
* @param OutputInterface|null $output
*/
public function __construct(InputInterface $input = null, OutputInterface $output = null)
{
if (!is_null($input)) {
$this->setInput($input);
}
if (!is_null($output)) {
$this->setOutput($output);
}
}
/**
* {@inheritdoc}
*/
public function getInput()
{
return $this->input;
}
/**
* {@inheritdoc}
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
return $this;
}
/**
* {@inheritdoc}
*/
public function getOutput()
{
return $this->output;
}
/**
* {@inheritdoc}
*/
public function setOutput(OutputInterface $output)
{
$this->output = $output;
return $this;
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Migration interface
*
* @author Richard Quadling <RQuadling@GMail.com>
*/
interface CreationInterface
{
/**
* CreationInterface constructor.
*
* @param InputInterface|null $input
* @param OutputInterface|null $output
*/
public function __construct(InputInterface $input = null, OutputInterface $output = null);
/**
* @param InputInterface $input
*
* @return CreationInterface
*/
public function setInput(InputInterface $input);
/**
* @param OutputInterface $output
*
* @return CreationInterface
*/
public function setOutput(OutputInterface $output);
/**
* @return InputInterface
*/
public function getInput();
/**
* @return OutputInterface
*/
public function getOutput();
/**
* Get the migration template.
*
* This will be the content that Phinx will amend to generate the migration file.
*
* @return string The content of the template for Phinx to amend.
*/
public function getMigrationTemplate();
/**
* Post Migration Creation.
*
* Once the migration file has been created, this method will be called, allowing any additional
* processing, specific to the template to be performed.
*
* @param string $migrationFilename The name of the newly created migration.
* @param string $className The class name.
* @param string $baseClassName The name of the base class.
* @return void
*/
public function postMigrationCreation($migrationFilename, $className, $baseClassName);
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
/**
* Exception class thrown when migrations cannot be reversed using the 'change'
* feature.
*
* @author Rob Morgan <robbym@gmail.com>
*/
class IrreversibleMigrationException extends \Exception
{
}

View File

@ -0,0 +1,32 @@
<?php
use $useClassName;
class $className extends $baseClassName
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
}
}

View File

@ -0,0 +1,215 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Db\Table;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Migration interface
*
* @author Rob Morgan <robbym@gmail.com>
*/
interface MigrationInterface
{
/**
* @var string
*/
const CHANGE = 'change';
/**
* @var string
*/
const UP = 'up';
/**
* @var string
*/
const DOWN = 'down';
/**
* Migrate Up
*
* @return void
*/
public function up();
/**
* Migrate Down
*
* @return void
*/
public function down();
/**
* Sets the database adapter.
*
* @param AdapterInterface $adapter Database Adapter
* @return MigrationInterface
*/
public function setAdapter(AdapterInterface $adapter);
/**
* Gets the database adapter.
*
* @return AdapterInterface
*/
public function getAdapter();
/**
* Sets the input object to be used in migration object
*
* @param InputInterface $input
* @return MigrationInterface
*/
public function setInput(InputInterface $input);
/**
* Gets the input object to be used in migration object
*
* @return InputInterface
*/
public function getInput();
/**
* Sets the output object to be used in migration object
*
* @param OutputInterface $output
* @return MigrationInterface
*/
public function setOutput(OutputInterface $output);
/**
* Gets the output object to be used in migration object
*
* @return OutputInterface
*/
public function getOutput();
/**
* Gets the name.
*
* @return string
*/
public function getName();
/**
* Sets the migration version number.
*
* @param float $version Version
* @return MigrationInterface
*/
public function setVersion($version);
/**
* Gets the migration version number.
*
* @return float
*/
public function getVersion();
/**
* Executes a SQL statement and returns the number of affected rows.
*
* @param string $sql SQL
* @return int
*/
public function execute($sql);
/**
* Executes a SQL statement and returns the result as an array.
*
* @param string $sql SQL
* @return array
*/
public function query($sql);
/**
* Executes a query and returns only one row as an array.
*
* @param string $sql SQL
* @return array
*/
public function fetchRow($sql);
/**
* Executes a query and returns an array of rows.
*
* @param string $sql SQL
* @return array
*/
public function fetchAll($sql);
/**
* Insert data into a table.
*
* @param string $tableName
* @param array $data
* @return void
*/
public function insert($tableName, $data);
/**
* Create a new database.
*
* @param string $name Database Name
* @param array $options Options
* @return void
*/
public function createDatabase($name, $options);
/**
* Drop a database.
*
* @param string $name Database Name
* @return void
*/
public function dropDatabase($name);
/**
* Checks to see if a table exists.
*
* @param string $tableName Table Name
* @return boolean
*/
public function hasTable($tableName);
/**
* Returns an instance of the <code>\Table</code> class.
*
* You can use this class to create and manipulate tables.
*
* @param string $tableName Table Name
* @param array $options Options
* @return Table
*/
public function table($tableName, $options);
}

View File

@ -0,0 +1,215 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Seed
*/
namespace Phinx\Seed;
use Phinx\Db\Table;
use Phinx\Db\Adapter\AdapterInterface;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Abstract Seed Class.
*
* It is expected that the seeds you write extend from this class.
*
* This abstract class proxies the various database methods to your specified
* adapter.
*
* @author Rob Morgan <robbym@gmail.com>
*/
abstract class AbstractSeed implements SeedInterface
{
/**
* @var AdapterInterface
*/
protected $adapter;
/**
* @var InputInterface
*/
protected $input;
/**
* @var OutputInterface
*/
protected $output;
/**
* Class Constructor.
*
* @param InputInterface $input
* @param OutputInterface $output
*/
final public function __construct(InputInterface $input = null, OutputInterface $output = null)
{
if (!is_null($input)){
$this->setInput($input);
}
if (!is_null($output)){
$this->setOutput($output);
}
$this->init();
}
/**
* Initialize method.
*
* @return void
*/
protected function init()
{
}
/**
* {@inheritdoc}
*/
public function run()
{
}
/**
* {@inheritdoc}
*/
public function setAdapter(AdapterInterface $adapter)
{
$this->adapter = $adapter;
return $this;
}
/**
* {@inheritdoc}
*/
public function getAdapter()
{
return $this->adapter;
}
/**
* {@inheritdoc}
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
return $this;
}
/**
* {@inheritdoc}
*/
public function getInput()
{
return $this->input;
}
/**
* {@inheritdoc}
*/
public function setOutput(OutputInterface $output)
{
$this->output = $output;
return $this;
}
/**
* {@inheritdoc}
*/
public function getOutput()
{
return $this->output;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return get_class($this);
}
/**
* {@inheritdoc}
*/
public function execute($sql)
{
return $this->getAdapter()->execute($sql);
}
/**
* {@inheritdoc}
*/
public function query($sql)
{
return $this->getAdapter()->query($sql);
}
/**
* {@inheritdoc}
*/
public function fetchRow($sql)
{
return $this->getAdapter()->fetchRow($sql);
}
/**
* {@inheritdoc}
*/
public function fetchAll($sql)
{
return $this->getAdapter()->fetchAll($sql);
}
/**
* {@inheritdoc}
*/
public function insert($table, $data)
{
// convert to table object
if (is_string($table)) {
$table = new Table($table, array(), $this->getAdapter());
}
return $table->insert($data)->save();
}
/**
* {@inheritdoc}
*/
public function hasTable($tableName)
{
return $this->getAdapter()->hasTable($tableName);
}
/**
* {@inheritdoc}
*/
public function table($tableName, $options = array())
{
return new Table($tableName, $options, $this->getAdapter());
}
}

View File

@ -0,0 +1,19 @@
<?php
use $useClassName;
class $className extends $baseClassName
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
{
}
}

View File

@ -0,0 +1,166 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Seed
*/
namespace Phinx\Seed;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Db\Table;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Seed interface
*
* @author Rob Morgan <robbym@gmail.com>
*/
interface SeedInterface
{
/**
* @var string
*/
const RUN = 'run';
/**
* Run the seeder.
*
* @return void
*/
public function run();
/**
* Sets the database adapter.
*
* @param AdapterInterface $adapter Database Adapter
* @return MigrationInterface
*/
public function setAdapter(AdapterInterface $adapter);
/**
* Gets the database adapter.
*
* @return AdapterInterface
*/
public function getAdapter();
/**
* Sets the input object to be used in migration object
*
* @param InputInterface $input
* @return MigrationInterface
*/
public function setInput(InputInterface $input);
/**
* Gets the input object to be used in migration object
*
* @return InputInterface
*/
public function getInput();
/**
* Sets the output object to be used in migration object
*
* @param OutputInterface $output
* @return MigrationInterface
*/
public function setOutput(OutputInterface $output);
/**
* Gets the output object to be used in migration object
*
* @return OutputInterface
*/
public function getOutput();
/**
* Gets the name.
*
* @return string
*/
public function getName();
/**
* Executes a SQL statement and returns the number of affected rows.
*
* @param string $sql SQL
* @return int
*/
public function execute($sql);
/**
* Executes a SQL statement and returns the result as an array.
*
* @param string $sql SQL
* @return array
*/
public function query($sql);
/**
* Executes a query and returns only one row as an array.
*
* @param string $sql SQL
* @return array
*/
public function fetchRow($sql);
/**
* Executes a query and returns an array of rows.
*
* @param string $sql SQL
* @return array
*/
public function fetchAll($sql);
/**
* Insert data into a table.
*
* @param string $tableName
* @param array $data
* @return void
*/
public function insert($tableName, $data);
/**
* Checks to see if a table exists.
*
* @param string $tableName Table Name
* @return boolean
*/
public function hasTable($tableName);
/**
* Returns an instance of the <code>\Table</code> class.
*
* You can use this class to create and manipulate tables.
*
* @param string $tableName Table Name
* @param array $options Options
* @return Table
*/
public function table($tableName, $options);
}

View File

@ -0,0 +1,190 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Util
*/
namespace Phinx\Util;
class Util
{
/**
* @var string
*/
const DATE_FORMAT = 'YmdHis';
/**
* @var string
*/
const MIGRATION_FILE_NAME_PATTERN = '/^\d+_([\w_]+).php$/i';
/**
* @var string
*/
const SEED_FILE_NAME_PATTERN = '/^([A-Z][a-z0-9]+).php$/i';
/**
* Gets the current timestamp string, in UTC.
*
* @return string
*/
public static function getCurrentTimestamp()
{
$dt = new \DateTime('now', new \DateTimeZone('UTC'));
return $dt->format(static::DATE_FORMAT);
}
/**
* Gets an array of all the existing migration class names.
*
* @return string
*/
public static function getExistingMigrationClassNames($path)
{
$classNames = array();
if (!is_dir($path)) {
return $classNames;
}
// filter the files to only get the ones that match our naming scheme
$phpFiles = glob($path . DIRECTORY_SEPARATOR . '*.php');
foreach ($phpFiles as $filePath) {
if (preg_match('/([0-9]+)_([_a-z0-9]*).php/', basename($filePath))) {
$classNames[] = static::mapFileNameToClassName(basename($filePath));
}
}
return $classNames;
}
/**
* Get the version from the beginning of a file name.
*
* @param string $fileName File Name
* @return string
*/
public static function getVersionFromFileName($fileName)
{
$matches = array();
preg_match('/^[0-9]+/', basename($fileName), $matches);
return $matches[0];
}
/**
* Turn migration names like 'CreateUserTable' into file names like
* '12345678901234_create_user_table.php' or 'LimitResourceNamesTo30Chars' into
* '12345678901234_limit_resource_names_to_30_chars.php'.
*
* @param string $className Class Name
* @return string
*/
public static function mapClassNameToFileName($className)
{
$arr = preg_split('/(?=[A-Z])/', $className);
unset($arr[0]); // remove the first element ('')
$fileName = static::getCurrentTimestamp() . '_' . strtolower(implode('_', $arr)) . '.php';
return $fileName;
}
/**
* Turn file names like '12345678901234_create_user_table.php' into class
* names like 'CreateUserTable'.
*
* @param string $fileName File Name
* @return string
*/
public static function mapFileNameToClassName($fileName)
{
$matches = array();
if (preg_match(static::MIGRATION_FILE_NAME_PATTERN, $fileName, $matches)) {
$fileName = $matches[1];
}
return str_replace(' ', '', ucwords(str_replace('_', ' ', $fileName)));
}
/**
* Check if a migration class name is unique regardless of the
* timestamp.
*
* This method takes a class name and a path to a migrations directory.
*
* Migration class names must be in CamelCase format.
* e.g: CreateUserTable or AddIndexToPostsTable.
*
* Single words are not allowed on their own.
*
* @param string $className Class Name
* @param string $path Path
* @return boolean
*/
public static function isUniqueMigrationClassName($className, $path)
{
$existingClassNames = static::getExistingMigrationClassNames($path);
return !(in_array($className, $existingClassNames));
}
/**
* Check if a migration/seed class name is valid.
*
* Migration & Seed class names must be in CamelCase format.
* e.g: CreateUserTable, AddIndexToPostsTable or UserSeeder.
*
* Single words are not allowed on their own.
*
* @param string $className Class Name
* @return boolean
*/
public static function isValidPhinxClassName($className)
{
return (bool) preg_match('/^([A-Z][a-z0-9]+)+$/', $className);
}
/**
* Check if a migration file name is valid.
*
* @param string $fileName File Name
* @return boolean
*/
public static function isValidMigrationFileName($fileName)
{
$matches = array();
return preg_match(static::MIGRATION_FILE_NAME_PATTERN, $fileName, $matches);
}
/**
* Check if a seed file name is valid.
*
* @param string $fileName File Name
* @return boolean
*/
public static function isValidSeedFileName($fileName)
{
$matches = array();
return preg_match(static::SEED_FILE_NAME_PATTERN, $fileName, $matches);
}
}

View File

@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration;
use InvalidArgumentException;
use Phinx\Db\Adapter\AdapterFactory;
abstract class Command extends \think\console\Command
{
public function getAdapter()
{
if (isset($this->adapter)) {
return $this->adapter;
}
$options = $this->getDbConfig();
$adapter = AdapterFactory::instance()->getAdapter($options['adapter'], $options);
if ($adapter->hasOption('table_prefix') || $adapter->hasOption('table_suffix')) {
$adapter = AdapterFactory::instance()->getWrapper('prefix', $adapter);
}
$this->adapter = $adapter;
return $adapter;
}
/**
* 获取数据库配置
* @return array
*/
protected function getDbConfig(): array
{
$default = $this->app->config->get('database.default');
$config = $this->app->config->get("database.connections.{$default}");
if (0 == $config['deploy']) {
$dbConfig = [
'adapter' => $config['type'],
'host' => $config['hostname'],
'name' => $config['database'],
'user' => $config['username'],
'pass' => $config['password'],
'port' => $config['hostport'],
'charset' => $config['charset'],
'table_prefix' => $config['prefix'],
];
} else {
$dbConfig = [
'adapter' => explode(',', $config['type'])[0],
'host' => explode(',', $config['hostname'])[0],
'name' => explode(',', $config['database'])[0],
'user' => explode(',', $config['username'])[0],
'pass' => explode(',', $config['password'])[0],
'port' => explode(',', $config['hostport'])[0],
'charset' => explode(',', $config['charset'])[0],
'table_prefix' => explode(',', $config['prefix'])[0],
];
}
$table = $this->app->config->get('database.migration_table', 'migrations');
$dbConfig['default_migration_table'] = $dbConfig['table_prefix'] . $table;
return $dbConfig;
}
protected function verifyMigrationDirectory(string $path)
{
if (!is_dir($path)) {
throw new InvalidArgumentException(sprintf('Migration directory "%s" does not exist', $path));
}
if (!is_writable($path)) {
throw new InvalidArgumentException(sprintf('Migration directory "%s" is not writable', $path));
}
}
}

View File

@ -0,0 +1,77 @@
<?php
namespace think\migration;
use InvalidArgumentException;
use Phinx\Util\Util;
use RuntimeException;
use think\App;
class Creator
{
protected $app;
public function __construct(App $app)
{
$this->app = $app;
}
public function create(string $className)
{
$path = $this->ensureDirectory();
if (!Util::isValidPhinxClassName($className)) {
throw new InvalidArgumentException(sprintf('The migration class name "%s" is invalid. Please use CamelCase format.', $className));
}
if (!Util::isUniqueMigrationClassName($className, $path)) {
throw new InvalidArgumentException(sprintf('The migration class name "%s" already exists', $className));
}
// Compute the file path
$fileName = Util::mapClassNameToFileName($className);
$filePath = $path . DIRECTORY_SEPARATOR . $fileName;
if (is_file($filePath)) {
throw new InvalidArgumentException(sprintf('The file "%s" already exists', $filePath));
}
// Verify that the template creation class (or the aliased class) exists and that it implements the required interface.
$aliasedClassName = null;
// Load the alternative template if it is defined.
$contents = file_get_contents($this->getTemplate());
// inject the class names appropriate to this migration
$contents = strtr($contents, [
'MigratorClass' => $className,
]);
if (false === file_put_contents($filePath, $contents)) {
throw new RuntimeException(sprintf('The file "%s" could not be written to', $path));
}
return $filePath;
}
protected function ensureDirectory()
{
$path = $this->app->getRootPath() . 'database' . DIRECTORY_SEPARATOR . 'migrations';
if (!is_dir($path) && !mkdir($path, 0755, true)) {
throw new InvalidArgumentException(sprintf('directory "%s" does not exist', $path));
}
if (!is_writable($path)) {
throw new InvalidArgumentException(sprintf('directory "%s" is not writable', $path));
}
return $path;
}
protected function getTemplate()
{
return __DIR__ . '/command/stubs/migrate.stub';
}
}

View File

@ -0,0 +1,313 @@
<?php
namespace think\migration;
use ArrayAccess;
use Faker\Generator as Faker;
class Factory implements ArrayAccess
{
/**
* The model definitions in the container.
*
* @var array
*/
protected $definitions = [];
/**
* The registered model states.
*
* @var array
*/
protected $states = [];
/**
* The registered after making callbacks.
*
* @var array
*/
protected $afterMaking = [];
/**
* The registered after creating callbacks.
*
* @var array
*/
protected $afterCreating = [];
/**
* The Faker instance for the builder.
*
* @var Faker
*/
protected $faker;
/**
* Create a new factory instance.
*
* @param Faker $faker
* @return void
*/
public function __construct(Faker $faker)
{
$this->faker = $faker;
}
/**
* Define a class with a given short-name.
*
* @param string $class
* @param string $name
* @param callable $attributes
* @return $this
*/
public function defineAs(string $class, string $name, callable $attributes)
{
return $this->define($class, $attributes, $name);
}
/**
* Define a class with a given set of attributes.
*
* @param string $class
* @param callable $attributes
* @param string $name
* @return $this
*/
public function define(string $class, callable $attributes, string $name = 'default')
{
$this->definitions[$class][$name] = $attributes;
return $this;
}
/**
* Define a state with a given set of attributes.
*
* @param string $class
* @param string $state
* @param callable|array $attributes
* @return $this
*/
public function state(string $class, string $state, $attributes)
{
$this->states[$class][$state] = $attributes;
return $this;
}
/**
* Define a callback to run after making a model.
*
* @param string $class
* @param callable $callback
* @param string $name
* @return $this
*/
public function afterMaking(string $class, callable $callback, string $name = 'default')
{
$this->afterMaking[$class][$name][] = $callback;
return $this;
}
/**
* Define a callback to run after making a model with given state.
*
* @param string $class
* @param string $state
* @param callable $callback
* @return $this
*/
public function afterMakingState(string $class, string $state, callable $callback)
{
return $this->afterMaking($class, $callback, $state);
}
/**
* Define a callback to run after creating a model.
*
* @param string $class
* @param callable $callback
* @param string $name
* @return $this
*/
public function afterCreating(string $class, callable $callback, string $name = 'default')
{
$this->afterCreating[$class][$name][] = $callback;
return $this;
}
/**
* Define a callback to run after creating a model with given state.
*
* @param string $class
* @param string $state
* @param callable $callback
* @return $this
*/
public function afterCreatingState(string $class, string $state, callable $callback)
{
return $this->afterCreating($class, $callback, $state);
}
/**
* Create an instance of the given model and persist it to the database.
*
* @param string $class
* @param array $attributes
* @return mixed
*/
public function create(string $class, array $attributes = [])
{
return $this->of($class)->create($attributes);
}
/**
* Create an instance of the given model and type and persist it to the database.
*
* @param string $class
* @param string $name
* @param array $attributes
* @return mixed
*/
public function createAs(string $class, string $name, array $attributes = [])
{
return $this->of($class, $name)->create($attributes);
}
/**
* Create an instance of the given model.
*
* @param string $class
* @param array $attributes
* @return mixed
*/
public function make(string $class, array $attributes = [])
{
return $this->of($class)->make($attributes);
}
/**
* Create an instance of the given model and type.
*
* @param string $class
* @param string $name
* @param array $attributes
* @return mixed
*/
public function makeAs(string $class, string $name, array $attributes = [])
{
return $this->of($class, $name)->make($attributes);
}
/**
* Get the raw attribute array for a given named model.
*
* @param string $class
* @param string $name
* @param array $attributes
* @return array
*/
public function rawOf(string $class, string $name, array $attributes = [])
{
return $this->raw($class, $attributes, $name);
}
/**
* Get the raw attribute array for a given model.
*
* @param string $class
* @param array $attributes
* @param string $name
* @return array
*/
public function raw(string $class, array $attributes = [], string $name = 'default')
{
return array_merge(
call_user_func($this->definitions[$class][$name], $this->faker), $attributes
);
}
/**
* Create a builder for the given model.
*
* @param string $class
* @param string $name
* @return FactoryBuilder
*/
public function of(string $class, string $name = 'default')
{
return new FactoryBuilder(
$class, $name, $this->definitions, $this->states,
$this->afterMaking, $this->afterCreating, $this->faker
);
}
/**
* Load factories from path.
*
* @param string $path
* @return $this
*/
public function load(string $path)
{
$factory = $this;
if (is_dir($path)) {
foreach (glob($path . '*.php') as $file) {
require $file;
}
}
return $factory;
}
/**
* Determine if the given offset exists.
*
* @param string $offset
* @return bool
*/
public function offsetExists($offset)
{
return isset($this->definitions[$offset]);
}
/**
* Get the value of the given offset.
*
* @param string $offset
* @return mixed
*/
public function offsetGet($offset)
{
return $this->make($offset);
}
/**
* Set the given offset to the given value.
*
* @param string $offset
* @param callable $value
* @return void
*/
public function offsetSet($offset, $value)
{
$this->define($offset, $value);
}
/**
* Unset the value at the given offset.
*
* @param string $offset
* @return void
*/
public function offsetUnset($offset)
{
unset($this->definitions[$offset]);
}
}

View File

@ -0,0 +1,434 @@
<?php
namespace think\migration;
use Faker\Generator as Faker;
use InvalidArgumentException;
use think\Collection;
use think\Model;
class FactoryBuilder
{
/**
* The model definitions in the container.
*
* @var array
*/
protected $definitions;
/**
* The model being built.
*
* @var string
*/
protected $class;
/**
* The name of the model being built.
*
* @var string
*/
protected $name = 'default';
/**
* The database connection on which the model instance should be persisted.
*
* @var string
*/
protected $connection;
/**
* The model states.
*
* @var array
*/
protected $states;
/**
* The model after making callbacks.
*
* @var array
*/
protected $afterMaking = [];
/**
* The model after creating callbacks.
*
* @var array
*/
protected $afterCreating = [];
/**
* The states to apply.
*
* @var array
*/
protected $activeStates = [];
/**
* The Faker instance for the builder.
*
* @var Faker
*/
protected $faker;
/**
* The number of models to build.
*
* @var int|null
*/
protected $amount = null;
/**
* Create an new builder instance.
*
* @param string $class
* @param string $name
* @param array $definitions
* @param array $states
* @param array $afterMaking
* @param array $afterCreating
* @param Faker $faker
* @return void
*/
public function __construct($class, $name, array $definitions, array $states,
array $afterMaking, array $afterCreating, Faker $faker)
{
$this->name = $name;
$this->class = $class;
$this->faker = $faker;
$this->states = $states;
$this->definitions = $definitions;
$this->afterMaking = $afterMaking;
$this->afterCreating = $afterCreating;
}
/**
* Set the amount of models you wish to create / make.
*
* @param int $amount
* @return $this
*/
public function times($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Set the state to be applied to the model.
*
* @param string $state
* @return $this
*/
public function state($state)
{
return $this->states([$state]);
}
/**
* Set the states to be applied to the model.
*
* @param array|mixed $states
* @return $this
*/
public function states($states)
{
$this->activeStates = is_array($states) ? $states : func_get_args();
return $this;
}
/**
* Set the database connection on which the model instance should be persisted.
*
* @param string $name
* @return $this
*/
public function connection($name)
{
$this->connection = $name;
return $this;
}
/**
* Create a model and persist it in the database if requested.
*
* @param array $attributes
* @return \Closure
*/
public function lazy(array $attributes = [])
{
return function () use ($attributes) {
return $this->create($attributes);
};
}
/**
* Create a collection of models and persist them to the database.
*
* @param array $attributes
* @return mixed
*/
public function create(array $attributes = [])
{
$results = $this->make($attributes);
if ($results instanceof Model) {
$this->store(new Collection([$results]));
$this->callAfterCreating(new Collection([$results]));
} else {
$this->store($results);
$this->callAfterCreating($results);
}
return $results;
}
/**
* Set the connection name on the results and store them.
*
* @param Collection $results
* @return void
*/
protected function store($results)
{
$results->each(function (Model $model) {
$model->save();
});
}
/**
* Create a collection of models.
*
* @param array $attributes
* @return mixed
*/
public function make(array $attributes = [])
{
if ($this->amount === null) {
return tap($this->makeInstance($attributes), function ($instance) {
$this->callAfterMaking(new Collection([$instance]));
});
}
if ($this->amount < 1) {
return (new $this->class)->toCollection();
}
$instances = (new $this->class)->toCollection(array_map(function () use ($attributes) {
return $this->makeInstance($attributes);
}, range(1, $this->amount)));
$this->callAfterMaking($instances);
return $instances;
}
/**
* Create an array of raw attribute arrays.
*
* @param array $attributes
* @return mixed
*/
public function raw(array $attributes = [])
{
if ($this->amount === null) {
return $this->getRawAttributes($attributes);
}
if ($this->amount < 1) {
return [];
}
return array_map(function () use ($attributes) {
return $this->getRawAttributes($attributes);
}, range(1, $this->amount));
}
/**
* Get a raw attributes array for the model.
*
* @param array $attributes
* @return mixed
*
* @throws \InvalidArgumentException
*/
protected function getRawAttributes(array $attributes = [])
{
if (!isset($this->definitions[$this->class][$this->name])) {
throw new InvalidArgumentException("Unable to locate factory with name [{$this->name}] [{$this->class}].");
}
$definition = call_user_func(
$this->definitions[$this->class][$this->name],
$this->faker, $attributes
);
return $this->expandAttributes(
array_merge($this->applyStates($definition, $attributes), $attributes)
);
}
/**
* Make an instance of the model with the given attributes.
*
* @param array $attributes
* @return Model
*/
protected function makeInstance(array $attributes = [])
{
return new $this->class(
$this->getRawAttributes($attributes)
);
}
/**
* Apply the active states to the model definition array.
*
* @param array $definition
* @param array $attributes
* @return array
*/
protected function applyStates(array $definition, array $attributes = [])
{
foreach ($this->activeStates as $state) {
if (!isset($this->states[$this->class][$state])) {
if ($this->stateHasAfterCallback($state)) {
continue;
}
throw new InvalidArgumentException("Unable to locate [{$state}] state for [{$this->class}].");
}
$definition = array_merge(
$definition,
$this->stateAttributes($state, $attributes)
);
}
return $definition;
}
/**
* Get the state attributes.
*
* @param string $state
* @param array $attributes
* @return array
*/
protected function stateAttributes($state, array $attributes)
{
$stateAttributes = $this->states[$this->class][$state];
if (!is_callable($stateAttributes)) {
return $stateAttributes;
}
return call_user_func(
$stateAttributes,
$this->faker, $attributes
);
}
/**
* Expand all attributes to their underlying values.
*
* @param array $attributes
* @return array
*/
protected function expandAttributes(array $attributes)
{
foreach ($attributes as &$attribute) {
if (is_callable($attribute) && !is_string($attribute) && !is_array($attribute)) {
$attribute = $attribute($attributes);
}
if ($attribute instanceof static) {
$attribute = $attribute->create()->getKey();
}
if ($attribute instanceof Model) {
$attribute = $attribute->getKey();
}
}
return $attributes;
}
/**
* Run after making callbacks on a collection of models.
*
* @param Collection $models
* @return void
*/
public function callAfterMaking($models)
{
$this->callAfter($this->afterMaking, $models);
}
/**
* Run after creating callbacks on a collection of models.
*
* @param Collection $models
* @return void
*/
public function callAfterCreating($models)
{
$this->callAfter($this->afterCreating, $models);
}
/**
* Call after callbacks for each model and state.
*
* @param array $afterCallbacks
* @param Collection $models
* @return void
*/
protected function callAfter(array $afterCallbacks, $models)
{
$states = array_merge([$this->name], $this->activeStates);
$models->each(function ($model) use ($states, $afterCallbacks) {
foreach ($states as $state) {
$this->callAfterCallbacks($afterCallbacks, $model, $state);
}
});
}
/**
* Call after callbacks for each model and state.
*
* @param array $afterCallbacks
* @param Model $model
* @param string $state
* @return void
*/
protected function callAfterCallbacks(array $afterCallbacks, $model, $state)
{
if (!isset($afterCallbacks[$this->class][$state])) {
return;
}
foreach ($afterCallbacks[$this->class][$state] as $callback) {
$callback($model, $this->faker);
}
}
/**
* Determine if the given state has an "after" callback.
*
* @param string $state
* @return bool
*/
protected function stateHasAfterCallback($state)
{
return isset($this->afterMaking[$this->class][$state]) ||
isset($this->afterCreating[$this->class][$state]);
}
}

View File

@ -0,0 +1,27 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration;
use Phinx\Migration\AbstractMigration;
use think\migration\db\Table;
class Migrator extends AbstractMigration
{
/**
* @param string $tableName
* @param array $options
* @return Table
*/
public function table($tableName, $options = [])
{
return new Table($tableName, $options, $this->getAdapter());
}
}

View File

@ -0,0 +1,18 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration;
use Phinx\Seed\AbstractSeed;
class Seeder extends AbstractSeed
{
}

View File

@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration;
use Faker\Factory as FakerFactory;
use Faker\Generator as FakerGenerator;
use think\migration\command\factory\Create as FactoryCreate;
use think\migration\command\migrate\Breakpoint as MigrateBreakpoint;
use think\migration\command\migrate\Create as MigrateCreate;
use think\migration\command\migrate\Rollback as MigrateRollback;
use think\migration\command\migrate\Run as MigrateRun;
use think\migration\command\migrate\Status as MigrateStatus;
use think\migration\command\seed\Create as SeedCreate;
use think\migration\command\seed\Run as SeedRun;
class Service extends \think\Service
{
public function boot()
{
$this->app->bind(FakerGenerator::class, function () {
return FakerFactory::create($this->app->config->get('app.faker_locale', 'zh_CN'));
});
$this->app->bind(Factory::class, function () {
return (new Factory($this->app->make(FakerGenerator::class)))->load($this->app->getRootPath() . 'database/factories/');
});
$this->app->bind('migration.creator', Creator::class);
$this->commands([
MigrateCreate::class,
MigrateRun::class,
MigrateRollback::class,
MigrateBreakpoint::class,
MigrateStatus::class,
SeedCreate::class,
SeedRun::class,
FactoryCreate::class,
]);
}
}

View File

@ -0,0 +1,146 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command;
use Phinx\Db\Adapter\AdapterFactory;
use Phinx\Db\Adapter\ProxyAdapter;
use Phinx\Migration\AbstractMigration;
use Phinx\Migration\MigrationInterface;
use Phinx\Util\Util;
use think\migration\Command;
use think\migration\Migrator;
abstract class Migrate extends Command
{
/**
* @var array
*/
protected $migrations;
protected function getPath()
{
return $this->app->getRootPath() . 'database' . DIRECTORY_SEPARATOR . 'migrations';
}
protected function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP)
{
$this->output->writeln('');
$this->output->writeln(' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . (MigrationInterface::UP === $direction ? 'migrating' : 'reverting') . '</comment>');
// Execute the migration and log the time elapsed.
$start = microtime(true);
$startTime = time();
$direction = (MigrationInterface::UP === $direction) ? MigrationInterface::UP : MigrationInterface::DOWN;
$migration->setAdapter($this->getAdapter());
// begin the transaction if the adapter supports it
if ($this->getAdapter()->hasTransactions()) {
$this->getAdapter()->beginTransaction();
}
// Run the migration
if (method_exists($migration, MigrationInterface::CHANGE)) {
if (MigrationInterface::DOWN === $direction) {
// Create an instance of the ProxyAdapter so we can record all
// of the migration commands for reverse playback
/** @var ProxyAdapter $proxyAdapter */
$proxyAdapter = AdapterFactory::instance()->getWrapper('proxy', $this->getAdapter());
$migration->setAdapter($proxyAdapter);
/** @noinspection PhpUndefinedMethodInspection */
$migration->change();
$proxyAdapter->executeInvertedCommands();
$migration->setAdapter($this->getAdapter());
} else {
/** @noinspection PhpUndefinedMethodInspection */
$migration->change();
}
} else {
$migration->{$direction}();
}
// commit the transaction if the adapter supports it
if ($this->getAdapter()->hasTransactions()) {
$this->getAdapter()->commitTransaction();
}
// Record it in the database
$this->getAdapter()
->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time()));
$end = microtime(true);
$this->output->writeln(' ==' . ' <info>' . $migration->getVersion() . ' ' . $migration->getName() . ':</info>' . ' <comment>' . (MigrationInterface::UP === $direction ? 'migrated' : 'reverted') . ' ' . sprintf('%.4fs', $end - $start) . '</comment>');
}
protected function getVersionLog()
{
return $this->getAdapter()->getVersionLog();
}
protected function getVersions()
{
return $this->getAdapter()->getVersions();
}
protected function getMigrations()
{
if (null === $this->migrations) {
$phpFiles = glob($this->getPath() . DIRECTORY_SEPARATOR . '*.php', defined('GLOB_BRACE') ? GLOB_BRACE : 0);
// filter the files to only get the ones that match our naming scheme
$fileNames = [];
/** @var Migrator[] $versions */
$versions = [];
foreach ($phpFiles as $filePath) {
if (Util::isValidMigrationFileName(basename($filePath))) {
$version = Util::getVersionFromFileName(basename($filePath));
if (isset($versions[$version])) {
throw new \InvalidArgumentException(sprintf('Duplicate migration - "%s" has the same version as "%s"', $filePath, $versions[$version]->getVersion()));
}
// convert the filename to a class name
$class = Util::mapFileNameToClassName(basename($filePath));
if (isset($fileNames[$class])) {
throw new \InvalidArgumentException(sprintf('Migration "%s" has the same name as "%s"', basename($filePath), $fileNames[$class]));
}
$fileNames[$class] = basename($filePath);
// load the migration file
/** @noinspection PhpIncludeInspection */
require_once $filePath;
if (!class_exists($class)) {
throw new \InvalidArgumentException(sprintf('Could not find class "%s" in file "%s"', $class, $filePath));
}
// instantiate it
$migration = new $class($version, $this->input, $this->output);
if (!($migration instanceof AbstractMigration)) {
throw new \InvalidArgumentException(sprintf('The class "%s" in file "%s" must extend \Phinx\Migration\AbstractMigration', $class, $filePath));
}
$versions[$version] = $migration;
}
}
ksort($versions);
$this->migrations = $versions;
}
return $this->migrations;
}
}

View File

@ -0,0 +1,73 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command;
use InvalidArgumentException;
use Phinx\Seed\AbstractSeed;
use Phinx\Util\Util;
use think\migration\Command;
use think\migration\Seeder;
abstract class Seed extends Command
{
/**
* @var array
*/
protected $seeds;
protected function getPath()
{
return $this->app->getRootPath() . 'database' . DIRECTORY_SEPARATOR . 'seeds';
}
public function getSeeds()
{
if (null === $this->seeds) {
$phpFiles = glob($this->getPath() . DIRECTORY_SEPARATOR . '*.php', defined('GLOB_BRACE') ? GLOB_BRACE : 0);
// filter the files to only get the ones that match our naming scheme
$fileNames = [];
/** @var Seeder[] $seeds */
$seeds = [];
foreach ($phpFiles as $filePath) {
if (Util::isValidSeedFileName(basename($filePath))) {
// convert the filename to a class name
$class = pathinfo($filePath, PATHINFO_FILENAME);
$fileNames[$class] = basename($filePath);
// load the seed file
/** @noinspection PhpIncludeInspection */
require_once $filePath;
if (!class_exists($class)) {
throw new InvalidArgumentException(sprintf('Could not find class "%s" in file "%s"', $class, $filePath));
}
// instantiate it
$seed = new $class($this->input, $this->output);
if (!($seed instanceof AbstractSeed)) {
throw new InvalidArgumentException(sprintf('The class "%s" in file "%s" must extend \Phinx\Seed\AbstractSeed', $class, $filePath));
}
$seeds[$class] = $seed;
}
}
ksort($seeds);
$this->seeds = $seeds;
}
return $this->seeds;
}
}

View File

@ -0,0 +1,82 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command\factory;
use InvalidArgumentException;
use Phinx\Util\Util;
use RuntimeException;
use think\console\Command;
use think\console\input\Argument as InputArgument;
class Create extends Command
{
protected function configure()
{
$this->setName('factory:create')
->setDescription('Create a new model factory')
->addArgument('name', InputArgument::REQUIRED, 'What is the name of the model?');
}
protected function handle()
{
$path = $this->getPath();
if (!file_exists($path)) {
mkdir($path, 0755, true);
}
if (!is_dir($path)) {
throw new InvalidArgumentException(sprintf('Factory directory "%s" does not exist', $path));
}
if (!is_writable($path)) {
throw new InvalidArgumentException(sprintf('Factory directory "%s" is not writable', $path));
}
$path = realpath($path);
$className = $this->input->getArgument('name');
if (!Util::isValidPhinxClassName($className)) {
throw new InvalidArgumentException(sprintf('The migration class name "%s" is invalid. Please use CamelCase format.', $className));
}
$filePath = $path . DIRECTORY_SEPARATOR . $className . '.php';
if (is_file($filePath)) {
throw new InvalidArgumentException(sprintf('The file "%s" already exists', $filePath));
}
// Load the alternative template if it is defined.
$contents = file_get_contents($this->getTemplate());
// inject the class names appropriate to this migration
$contents = strtr($contents, [
'"ModelClass"' => "\\app\\model\\" . $className . '::class',
]);
if (false === file_put_contents($filePath, $contents)) {
throw new RuntimeException(sprintf('The file "%s" could not be written to', $path));
}
$this->output->writeln('<info>created</info> .' . str_replace(getcwd(), '', $filePath));
}
protected function getTemplate()
{
return __DIR__ . '/../stubs/factory.stub';
}
protected function getPath()
{
return $this->app->getRootPath() . 'database' . DIRECTORY_SEPARATOR . 'factories';
}
}

View File

@ -0,0 +1,92 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command\migrate;
use think\console\Input;
use think\console\input\Option as InputOption;
use think\console\Output;
use think\migration\command\Migrate;
class Breakpoint extends Migrate
{
protected function configure()
{
$this->setName('migrate:breakpoint')
->setDescription('Manage breakpoints')
->addOption('--target', '-t', InputOption::VALUE_REQUIRED, 'The version number to set or clear a breakpoint against')
->addOption('--remove-all', '-r', InputOption::VALUE_NONE, 'Remove all breakpoints')
->setHelp(<<<EOT
The <info>breakpoint</info> command allows you to set or clear a breakpoint against a specific target to inhibit rollbacks beyond a certain target.
If no target is supplied then the most recent migration will be used.
You cannot specify un-migrated targets
<info>php think migrate:breakpoint</info>
<info>php think migrate:breakpoint -t 20110103081132</info>
<info>php think migrate:breakpoint -r</info>
EOT
);
}
protected function execute(Input $input, Output $output)
{
$version = $input->getOption('target');
$removeAll = $input->getOption('remove-all');
if ($version && $removeAll) {
throw new \InvalidArgumentException('Cannot toggle a breakpoint and remove all breakpoints at the same time.');
}
// Remove all breakpoints
if ($removeAll) {
$this->removeBreakpoints();
} else {
// Toggle the breakpoint.
$this->toggleBreakpoint($version);
}
}
protected function toggleBreakpoint($version)
{
$migrations = $this->getMigrations();
$versions = $this->getVersionLog();
if (empty($versions) || empty($migrations)) {
return;
}
if (null === $version) {
$lastVersion = end($versions);
$version = $lastVersion['version'];
}
if (0 != $version && !isset($migrations[$version])) {
$this->output->writeln(sprintf('<comment>warning</comment> %s is not a valid version', $version));
return;
}
$this->getAdapter()->toggleBreakpoint($migrations[$version]);
$versions = $this->getVersionLog();
$this->output->writeln(' Breakpoint ' . ($versions[$version]['breakpoint'] ? 'set' : 'cleared') . ' for <info>' . $version . '</info>' . ' <comment>' . $migrations[$version]->getName() . '</comment>');
}
/**
* Remove all breakpoints
*
* @return void
*/
protected function removeBreakpoints()
{
$this->output->writeln(sprintf(' %d breakpoints cleared.', $this->getAdapter()->resetAllBreakpoints()));
}
}

View File

@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | TopThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command\migrate;
use InvalidArgumentException;
use RuntimeException;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument as InputArgument;
use think\console\Output;
use think\migration\Creator;
class Create extends Command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('migrate:create')
->setDescription('Create a new migration')
->addArgument('name', InputArgument::REQUIRED, 'What is the name of the migration?')
->setHelp(sprintf('%sCreates a new database migration%s', PHP_EOL, PHP_EOL));
}
/**
* Create the new migration.
*
* @param Input $input
* @param Output $output
* @return void
* @throws InvalidArgumentException
* @throws RuntimeException
*/
protected function execute(Input $input, Output $output)
{
/** @var Creator $creator */
$creator = $this->app->get('migration.creator');
$className = $input->getArgument('name');
$path = $creator->create($className);
$output->writeln('<info>created</info> .' . str_replace(getcwd(), '', realpath($path)));
}
}

View File

@ -0,0 +1,146 @@
<?php
// +----------------------------------------------------------------------
// | TopThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command\migrate;
use Phinx\Migration\MigrationInterface;
use think\console\input\Option as InputOption;
use think\console\Input;
use think\console\Output;
use think\migration\command\Migrate;
class Rollback extends Migrate
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('migrate:rollback')
->setDescription('Rollback the last or to a specific migration')
->addOption('--target', '-t', InputOption::VALUE_REQUIRED, 'The version number to rollback to')
->addOption('--date', '-d', InputOption::VALUE_REQUIRED, 'The date to rollback to')
->addOption('--force', '-f', InputOption::VALUE_NONE, 'Force rollback to ignore breakpoints')
->setHelp(<<<EOT
The <info>migrate:rollback</info> command reverts the last migration, or optionally up to a specific version
<info>php think migrate:rollback</info>
<info>php think migrate:rollback -t 20111018185412</info>
<info>php think migrate:rollback -d 20111018</info>
<info>php think migrate:rollback -v</info>
EOT
);
}
/**
* Rollback the migration.
*
* @param Input $input
* @param Output $output
* @return void
*/
protected function execute(Input $input, Output $output)
{
$version = $input->getOption('target');
$date = $input->getOption('date');
$force = !!$input->getOption('force');
// rollback the specified environment
$start = microtime(true);
if (null !== $date) {
$this->rollbackToDateTime(new \DateTime($date), $force);
} else {
$this->rollback($version, $force);
}
$end = microtime(true);
$output->writeln('');
$output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
}
protected function rollback($version = null, $force = false)
{
$migrations = $this->getMigrations();
$versionLog = $this->getVersionLog();
$versions = array_keys($versionLog);
ksort($migrations);
sort($versions);
// Check we have at least 1 migration to revert
if (empty($versions) || $version == end($versions)) {
$this->output->writeln('<error>No migrations to rollback</error>');
return;
}
// If no target version was supplied, revert the last migration
if (null === $version) {
// Get the migration before the last run migration
$prev = count($versions) - 2;
$version = $prev < 0 ? 0 : $versions[$prev];
} else {
// Get the first migration number
$first = $versions[0];
// If the target version is before the first migration, revert all migrations
if ($version < $first) {
$version = 0;
}
}
// Check the target version exists
if (0 !== $version && !isset($migrations[$version])) {
$this->output->writeln("<error>Target version ($version) not found</error>");
return;
}
// Revert the migration(s)
krsort($migrations);
foreach ($migrations as $migration) {
if ($migration->getVersion() <= $version) {
break;
}
if (in_array($migration->getVersion(), $versions)) {
if (isset($versionLog[$migration->getVersion()]) && 0 != $versionLog[$migration->getVersion()]['breakpoint'] && !$force) {
$this->output->writeln('<error>Breakpoint reached. Further rollbacks inhibited.</error>');
break;
}
$this->executeMigration($migration, MigrationInterface::DOWN);
}
}
}
protected function rollbackToDateTime(\DateTime $dateTime, $force = false)
{
$versions = $this->getVersions();
$dateString = $dateTime->format('YmdHis');
sort($versions);
$earlierVersion = null;
$availableMigrations = array_filter($versions, function ($version) use ($dateString, &$earlierVersion) {
if ($version <= $dateString) {
$earlierVersion = $version;
}
return $version >= $dateString;
});
if (count($availableMigrations) > 0) {
if (is_null($earlierVersion)) {
$this->output->writeln('Rolling back all migrations');
$migration = 0;
} else {
$this->output->writeln('Rolling back to version ' . $earlierVersion);
$migration = $earlierVersion;
}
$this->rollback($migration, $force);
}
}
}

View File

@ -0,0 +1,140 @@
<?php
// +----------------------------------------------------------------------
// | TopThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command\migrate;
use Phinx\Migration\MigrationInterface;
use think\console\Input;
use think\console\input\Option as InputOption;
use think\console\Output;
use think\migration\command\Migrate;
class Run extends Migrate
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('migrate:run')
->setDescription('Migrate the database')
->addOption('--target', '-t', InputOption::VALUE_REQUIRED, 'The version number to migrate to')
->addOption('--date', '-d', InputOption::VALUE_REQUIRED, 'The date to migrate to')
->setHelp(<<<EOT
The <info>migrate:run</info> command runs all available migrations, optionally up to a specific version
<info>php think migrate:run</info>
<info>php think migrate:run -t 20110103081132</info>
<info>php think migrate:run -d 20110103</info>
<info>php think migrate:run -v</info>
EOT
);
}
/**
* Migrate the database.
*
* @param Input $input
* @param Output $output
*/
protected function execute(Input $input, Output $output)
{
$version = $input->getOption('target');
$date = $input->getOption('date');
// run the migrations
$start = microtime(true);
if (null !== $date) {
$this->migrateToDateTime(new \DateTime($date));
} else {
$this->migrate($version);
}
$end = microtime(true);
$output->writeln('');
$output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
}
public function migrateToDateTime(\DateTime $dateTime)
{
$versions = array_keys($this->getMigrations());
$dateString = $dateTime->format('YmdHis');
$outstandingMigrations = array_filter($versions, function ($version) use ($dateString) {
return $version <= $dateString;
});
if (count($outstandingMigrations) > 0) {
$migration = max($outstandingMigrations);
$this->output->writeln('Migrating to version ' . $migration);
$this->migrate($migration);
}
}
protected function migrate($version = null)
{
$migrations = $this->getMigrations();
$versions = $this->getVersions();
$current = $this->getCurrentVersion();
if (empty($versions) && empty($migrations)) {
return;
}
if (null === $version) {
$version = max(array_merge($versions, array_keys($migrations)));
} else {
if (0 != $version && !isset($migrations[$version])) {
$this->output->writeln(sprintf('<comment>warning</comment> %s is not a valid version', $version));
return;
}
}
// are we migrating up or down?
$direction = $version > $current ? MigrationInterface::UP : MigrationInterface::DOWN;
if ($direction === MigrationInterface::DOWN) {
// run downs first
krsort($migrations);
foreach ($migrations as $migration) {
if ($migration->getVersion() <= $version) {
break;
}
if (in_array($migration->getVersion(), $versions)) {
$this->executeMigration($migration, MigrationInterface::DOWN);
}
}
}
ksort($migrations);
foreach ($migrations as $migration) {
if ($migration->getVersion() > $version) {
break;
}
if (!in_array($migration->getVersion(), $versions)) {
$this->executeMigration($migration, MigrationInterface::UP);
}
}
}
protected function getCurrentVersion()
{
$versions = $this->getVersions();
$version = 0;
if (!empty($versions)) {
$version = end($versions);
}
return $version;
}
}

View File

@ -0,0 +1,124 @@
<?php
// +----------------------------------------------------------------------
// | TopThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command\migrate;
use think\console\input\Option as InputOption;
use think\console\Input;
use think\console\Output;
use think\migration\command\Migrate;
class Status extends Migrate
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('migrate:status')
->setDescription('Show migration status')
->addOption('--format', '-f', InputOption::VALUE_REQUIRED, 'The output format: text or json. Defaults to text.')
->setHelp(<<<EOT
The <info>migrate:status</info> command prints a list of all migrations, along with their current status
<info>php think migrate:status</info>
<info>php think migrate:status -f json</info>
EOT
);
}
/**
* Show the migration status.
*
* @param Input $input
* @param Output $output
* @return integer 0 if all migrations are up, or an error code
*/
protected function execute(Input $input, Output $output)
{
$format = $input->getOption('format');
if (null !== $format) {
$output->writeln('<info>using format</info> ' . $format);
}
// print the status
return $this->printStatus($format);
}
protected function printStatus($format = null)
{
$output = $this->output;
$migrations = [];
if (count($this->getMigrations())) {
// TODO - rewrite using Symfony Table Helper as we already have this library
// included and it will fix formatting issues (e.g drawing the lines)
$output->writeln('');
$output->writeln(' Status Migration ID Started Finished Migration Name ');
$output->writeln('----------------------------------------------------------------------------------');
$versions = $this->getVersionLog();
$maxNameLength = $versions ? max(array_map(function ($version) {
return strlen($version['migration_name']);
}, $versions)) : 0;
foreach ($this->getMigrations() as $migration) {
$version = array_key_exists($migration->getVersion(), $versions) ? $versions[$migration->getVersion()] : false;
if ($version) {
$status = ' <info>up</info> ';
} else {
$status = ' <error>down</error> ';
}
$maxNameLength = max($maxNameLength, strlen($migration->getName()));
$output->writeln(sprintf('%s %14.0f %19s %19s <comment>%s</comment>', $status, $migration->getVersion(), $version['start_time'], $version['end_time'], $migration->getName()));
if ($version && $version['breakpoint']) {
$output->writeln(' <error>BREAKPOINT SET</error>');
}
$migrations[] = [
'migration_status' => trim(strip_tags($status)),
'migration_id' => sprintf('%14.0f', $migration->getVersion()),
'migration_name' => $migration->getName()
];
unset($versions[$migration->getVersion()]);
}
if (count($versions)) {
foreach ($versions as $missing => $version) {
$output->writeln(sprintf(' <error>up</error> %14.0f %19s %19s <comment>%s</comment> <error>** MISSING **</error>', $missing, $version['start_time'], $version['end_time'], str_pad($version['migration_name'], $maxNameLength, ' ')));
if ($version && $version['breakpoint']) {
$output->writeln(' <error>BREAKPOINT SET</error>');
}
}
}
} else {
// there are no migrations
$output->writeln('');
$output->writeln('There are no available migrations. Try creating one using the <info>create</info> command.');
}
// write an empty line
$output->writeln('');
if ($format !== null) {
switch ($format) {
case 'json':
$output->writeln(json_encode([
'pending_count' => count($this->getMigrations()),
'migrations' => $migrations
]));
break;
default:
$output->writeln('<info>Unsupported format: ' . $format . '</info>');
}
}
}
}

View File

@ -0,0 +1,83 @@
<?php
// +----------------------------------------------------------------------
// | TopThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command\seed;
use Phinx\Util\Util;
use think\console\Input;
use think\console\input\Argument as InputArgument;
use think\console\Output;
use think\migration\command\Seed;
class Create extends Seed
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('seed:create')
->setDescription('Create a new database seeder')
->addArgument('name', InputArgument::REQUIRED, 'What is the name of the seeder?')
->setHelp(sprintf('%sCreates a new database seeder%s', PHP_EOL, PHP_EOL));
}
/**
* Create the new seeder.
*
* @param Input $input
* @param Output $output
* @return void
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
protected function execute(Input $input, Output $output)
{
$path = $this->getPath();
if (!file_exists($path)) {
mkdir($path, 0755, true);
}
$this->verifyMigrationDirectory($path);
$path = realpath($path);
$className = $input->getArgument('name');
if (!Util::isValidPhinxClassName($className)) {
throw new \InvalidArgumentException(sprintf('The seed class name "%s" is invalid. Please use CamelCase format', $className));
}
// Compute the file path
$filePath = $path . DIRECTORY_SEPARATOR . $className . '.php';
if (is_file($filePath)) {
throw new \InvalidArgumentException(sprintf('The file "%s" already exists', basename($filePath)));
}
// inject the class names appropriate to this seeder
$contents = file_get_contents($this->getTemplate());
$classes = [
'SeederClass' => $className,
];
$contents = strtr($contents, $classes);
if (false === file_put_contents($filePath, $contents)) {
throw new \RuntimeException(sprintf('The file "%s" could not be written to', $path));
}
$output->writeln('<info>created</info> .' . str_replace(getcwd(), '', $filePath));
}
protected function getTemplate()
{
return __DIR__ . '/../stubs/seed.stub';
}
}

View File

@ -0,0 +1,107 @@
<?php
// +----------------------------------------------------------------------
// | TopThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\command\seed;
use Phinx\Seed\SeedInterface;
use think\console\Input;
use think\console\input\Option as InputOption;
use think\console\Output;
use think\migration\command\Seed;
class Run extends Seed
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('seed:run')
->setDescription('Run database seeders')
->addOption('--seed', '-s', InputOption::VALUE_REQUIRED, 'What is the name of the seeder?')
->setHelp(<<<EOT
The <info>seed:run</info> command runs all available or individual seeders
<info>php think seed:run</info>
<info>php think seed:run -s UserSeeder</info>
<info>php think seed:run -v</info>
EOT
);
}
/**
* Run database seeders.
*
* @param Input $input
* @param Output $output
* @return void
*/
protected function execute(Input $input, Output $output)
{
$seed = $input->getOption('seed');
// run the seed(ers)
$start = microtime(true);
$this->seed($seed);
$end = microtime(true);
$output->writeln('');
$output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
}
public function seed($seed = null)
{
$seeds = $this->getSeeds();
if (null === $seed) {
// run all seeders
foreach ($seeds as $seeder) {
if (array_key_exists($seeder->getName(), $seeds)) {
$this->executeSeed($seeder);
}
}
} else {
// run only one seeder
if (array_key_exists($seed, $seeds)) {
$this->executeSeed($seeds[$seed]);
} else {
throw new \InvalidArgumentException(sprintf('The seed class "%s" does not exist', $seed));
}
}
}
protected function executeSeed(SeedInterface $seed)
{
$this->output->writeln('');
$this->output->writeln(' ==' . ' <info>' . $seed->getName() . ':</info>' . ' <comment>seeding</comment>');
// Execute the seeder and log the time elapsed.
$start = microtime(true);
$seed->setAdapter($this->getAdapter());
// begin the transaction if the adapter supports it
if ($this->getAdapter()->hasTransactions()) {
$this->getAdapter()->beginTransaction();
}
// Run the seeder
if (method_exists($seed, SeedInterface::RUN)) {
$seed->run();
}
// commit the transaction if the adapter supports it
if ($this->getAdapter()->hasTransactions()) {
$this->getAdapter()->commitTransaction();
}
$end = microtime(true);
$this->output->writeln(' ==' . ' <info>' . $seed->getName() . ':</info>' . ' <comment>seeded' . ' ' . sprintf('%.4fs', $end - $start) . '</comment>');
}
}

View File

@ -0,0 +1,11 @@
<?php
use Faker\Generator as Faker;
use think\migration\Factory;
/** @var Factory $factory */
$factory->define("ModelClass", function (Faker $faker) {
return [
//
];
});

View File

@ -0,0 +1,33 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class MigratorClass extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
}
}

View File

@ -0,0 +1,19 @@
<?php
use think\migration\Seeder;
class SeederClass extends Seeder
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
{
}
}

View File

@ -0,0 +1,171 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\migration\db;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Db\Adapter\MysqlAdapter;
class Column extends \Phinx\Db\Table\Column
{
protected $unique = false;
public function setNullable()
{
return $this->setNull(true);
}
public function setUnsigned()
{
return $this->setSigned(false);
}
public function setUnique()
{
$this->unique = true;
return $this;
}
public function getUnique()
{
return $this->unique;
}
public function isUnique()
{
return $this->getUnique();
}
public static function make($name, $type, $options = [])
{
$column = new self();
$column->setName($name);
$column->setType($type);
$column->setOptions($options);
return $column;
}
public static function bigInteger($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_BIG_INTEGER);
}
public static function binary($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_BLOB);
}
public static function boolean($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_BOOLEAN);
}
public static function char($name, $length = 255)
{
return self::make($name, AdapterInterface::PHINX_TYPE_CHAR, compact('length'));
}
public static function date($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_DATE);
}
public static function dateTime($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_DATETIME);
}
public static function decimal($name, $precision = 8, $scale = 2)
{
return self::make($name, AdapterInterface::PHINX_TYPE_DECIMAL, compact('precision', 'scale'));
}
public static function enum($name, array $values)
{
return self::make($name, AdapterInterface::PHINX_TYPE_ENUM, compact('values'));
}
public static function float($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_FLOAT);
}
public static function integer($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_INTEGER);
}
public static function json($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_JSON);
}
public static function jsonb($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_JSONB);
}
public static function longText($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TEXT, ['length' => MysqlAdapter::TEXT_LONG]);
}
public static function mediumInteger($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_INTEGER, ['length' => MysqlAdapter::INT_MEDIUM]);
}
public static function mediumText($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TEXT, ['length' => MysqlAdapter::TEXT_MEDIUM]);
}
public static function smallInteger($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_INTEGER, ['length' => MysqlAdapter::INT_SMALL]);
}
public static function string($name, $length = 255)
{
return self::make($name, AdapterInterface::PHINX_TYPE_STRING, compact('length'));
}
public static function text($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TEXT);
}
public static function time($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TIME);
}
public static function tinyInteger($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_INTEGER, ['length' => MysqlAdapter::INT_TINY]);
}
public static function unsignedInteger($name)
{
return self::integer($name)->setUnSigned();
}
public static function timestamp($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_TIMESTAMP);
}
public static function uuid($name)
{
return self::make($name, AdapterInterface::PHINX_TYPE_UUID);
}
}

Some files were not shown because too many files have changed in this diff Show More