Skip to content

Commit e7ad584

Browse files
authored
Merge pull request #2 from OliveCMS/v2.1
V2.1
2 parents e2ae2e0 + d612de5 commit e7ad584

File tree

6 files changed

+87
-9
lines changed

6 files changed

+87
-9
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## v2.1
4+
5+
* add limit for find method
6+
* fix mysql rel problem
7+
* fix mysql insert and update string poblem
8+
* update doc
9+
* move colorconsole to dev
10+
311
## v2.0
412

513
UDSM now have D2T (Database 2 Table) mode! this option is a solution for when Addon can not auto create database! with this mode, app can create auto database.

addons/MySQL/Point.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function createColumn($db, $table, $name, $options)
170170
$d = $options['__udms_rel'];
171171
$e = key($d);
172172
$c = $d[$e];
173-
$options = $ui[$this->getCore->ot][$c];
173+
$options = $ui[$e][$c];
174174
$rel_detect = true;
175175
}
176176
if (isset($options['__udms_config']['mysql_' . $this->type])) {
@@ -267,7 +267,7 @@ public function insert($db, $table, $data)
267267
$options = $ui[$e][$c];
268268
}
269269
if (in_array(strtoupper($options['type']), $this->str_type)) {
270-
$data[$col] = '\'' . $value . '\'';
270+
$data[$col] = '\'' . str_replace(['\\', '\'', '"'], ['\\\\', '\\\'', '\\"'], $value) . '\'';
271271
}
272272
}
273273
}
@@ -291,7 +291,7 @@ public function update($db, $table, $uid, $data)
291291
$options = $ui[$e][$c];
292292
}
293293
if (in_array(strtoupper($options['type']), $this->str_type)) {
294-
$data[$col] = '\'' . $value . '\'';
294+
$data[$col] = '\'' . str_replace(['\\', '\'', '"'], ['\\\\', '\\\'', '\\"'], $value) . '\'';
295295
}
296296
}
297297
$do[] = "`$col` = " . $data[$col];

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"require": {
77
"php": ">=5.5",
88
"mongodb/mongodb": "^1.4",
9-
"olive-cms/tools": "^1.0",
9+
"olive-cms/tools": "^1.0"
10+
},
11+
"require-dev": {
1012
"olive-cms/colorconsole": "^1.0"
1113
},
1214
"autoload": {

doc/01-usage.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,38 @@ if($udms->school->availableColumnRule()) {
302302
$udms->school->student->createColumn('studnet',
303303
[] // config
304304
);
305+
/**
306+
* config available:
307+
* @param type -> [int, text]
308+
* @param length -> (0==ultimate)
309+
* @param index -> [primary]
310+
* @param auto -> [start => int, add => int]
311+
* @param __udms_rel -> [table => column]
312+
*/
313+
/*
314+
# example 1:
315+
$udms->school->classes->createColumn('id',
316+
[
317+
'type' => 'int',
318+
'lenght' => 8,
319+
'index' => 'primary',
320+
'auto' => [
321+
'start' => 1000000,
322+
'add' => 367
323+
]
324+
]
325+
);
326+
327+
# example 2:
328+
329+
$udms->school->classes->createColumn('t_id',
330+
[
331+
'__udms_rel' => [
332+
'teacher' => 'id'
333+
]
334+
]
335+
);
336+
*/
305337
```
306338

307339
### Exists Column
@@ -419,7 +451,8 @@ $list_1 = $udms->school->student->get(
419451
'relation' => false,
420452
'sort' => [
421453
'lname' => SORT_ASC
422-
]
454+
],
455+
'limit' => 5
423456
]
424457
);
425458
/* output array

src/Core.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,16 @@ public function createDatabase($name, $option = [])
380380
$dl[] = $name;
381381
$this->setD2T($dl);
382382
}
383+
$ui = $this->getAppModel();
384+
if (! isset($ui[$name])) {
385+
$ui[$name] = [];
386+
$this->setAppModel($ui);
387+
}
388+
$ud = $this->getAppModelData();
389+
if (! isset($ud[$name])) {
390+
$ud[$name] = [];
391+
$this->setAppModelData($ud);
392+
}
383393
}
384394

385395
public function dropDatabase($name)
@@ -395,6 +405,16 @@ public function dropDatabase($name)
395405
}
396406
$this->setD2T(array_diff($this->getD2T(), [$name]));
397407
}
408+
$ui = $this->getAppModel();
409+
if (isset($ui[$name])) {
410+
unset($ui[$name]);
411+
$this->setAppModel($ui);
412+
}
413+
$ud = $this->getAppModelData();
414+
if (isset($ud[$name])) {
415+
unset($ud[$name]);
416+
$this->setAppModelData($ud);
417+
}
398418
} else {
399419
throw new UException($this->getUCPath(), 'your database name has not exists (' . $name . ')', 112);
400420
}
@@ -437,6 +457,19 @@ public function renameDatabase($name, $to)
437457
$dl[$key] = $to;
438458
$this->setD2T($dl);
439459
}
460+
461+
$ui = $this->getAppModel();
462+
if (isset($ui[$name])) {
463+
$ui[$to] = $ui[$name];
464+
unset($ui[$name]);
465+
$this->setAppModel($ui);
466+
}
467+
$ud = $this->getAppModelData();
468+
if (isset($ud[$name])) {
469+
$ud[$to] = $ud[$name];
470+
unset($ud[$name]);
471+
$this->setAppModelData($ud);
472+
}
440473
}
441474

442475
public function __get($name)

src/Model/Table.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,9 @@ public function createColumn($name, $options = [])
119119
$this->getCore->execute->createColumn($this->dbname, $this->table, $name, $options);
120120
$ud = $this->getCore->getDatabaseModelData($this->dbname);
121121
if (isset($options['auto'])) {
122-
if (count($options['auto']) == 0) {
123-
$start = 1;
124-
$add = 1;
125-
} else {
122+
$start = 1;
123+
$add = 1;
124+
if (count($options['auto']) > 0) {
126125
if (isset($options['auto']['start'])) {
127126
$start = $options['auto']['start'];
128127
}
@@ -285,6 +284,9 @@ public function find($filters = [], $options = [])
285284
}
286285
$return = call_user_func_array([$this, 'orderBy'], $args);
287286
}
287+
if (isset($options['limit']) and is_int($options['limit']) and $options['limit'] > 0) {
288+
$return = array_slice($return, 0, $options['limit']);
289+
}
288290

289291
return $return;
290292
}

0 commit comments

Comments
 (0)