Skip to content

Commit 3088ebf

Browse files
authored
Merge pull request #1102 from phalcon/3.2.x
3.2.5
2 parents 04ccd74 + 114b87b commit 3088ebf

39 files changed

+1929
-9
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ env:
3838
- TEST_DB_POSTGRESQL_USER="postgres"
3939
- TEST_DB_POSTGRESQL_PASSWD=""
4040
- TEST_DB_POSTGRESQL_NAME="devtools"
41+
- TEST_DB_POSTGRESQL_SCHEMA="public"
4142
- TEST_DB_MYSQL_DSN="mysql:host=127.0.0.1;dbname=devtools"
4243
- TEST_DB_MYSQL_HOST="127.0.0.1"
4344
- TEST_DB_MYSQL_PORT="3306"

scripts/Phalcon/Builder/AllModels.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ public function build()
6262

6363
$this->options->offsetSet('directory', $this->path->getRootPath());
6464

65-
$config = $this->getConfig();
65+
if (gettype($this->options->get('config')) == 'object') {
66+
$config = $this->options->get('config');
67+
} else {
68+
$config = $this->getConfig();
69+
}
6670

6771
if (!$modelsDir = $this->options->get('modelsDir')) {
6872
if (!isset($config->application->modelsDir)) {
@@ -195,6 +199,7 @@ public function build()
195199

196200
$modelBuilder = new Model([
197201
'name' => $name,
202+
'config' => $config,
198203
'schema' => $schema,
199204
'extends' => $this->options->get('extends'),
200205
'namespace' => $this->options->get('namespace'),

scripts/Phalcon/Builder/Model.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ public function build()
146146
$this->path->setRootPath($this->options->get('directory'));
147147
}
148148

149-
$config = $this->getConfig();
149+
if (gettype($this->options->get('config')) == 'object') {
150+
$config = $this->options->get('config');
151+
} else {
152+
$config = $this->getConfig();
153+
}
150154

151155
if (!$modelsDir = $this->options->get('modelsDir')) {
152156
if (!$config->get('application') || !isset($config->get('application')->modelsDir)) {

scripts/Phalcon/Commands/Builtin/Model.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function getPossibleParams()
4646
return [
4747
'name=s' => 'Table name',
4848
'schema=s' => 'Name of the schema [optional]',
49+
'config=s' => 'Configuration file [optional]',
4950
'namespace=s' => "Model's namespace [optional]",
5051
'get-set' => 'Attributes will be protected and have setters/getters [optional]',
5152
'extends=s' => 'Model extends the class name supplied [optional]',
@@ -74,10 +75,32 @@ public function run(array $parameters)
7475
$name = $this->getOption(['name', 1]);
7576
$className = Utils::camelize(isset($parameters[1]) ? $parameters[1] : $name, '_-');
7677

78+
if ($this->isReceivedOption('config')) {
79+
if (false == $this->path->isAbsolutePath($this->getOption('config'))) {
80+
$configPath = $this->path->getRootPath() . $this->getOption('config');
81+
} else {
82+
$configPath = $this->getOption('config');
83+
}
84+
85+
if (preg_match('/.*(:?\.ini)(?:\s)?$/i', $configPath)) {
86+
$config = new ConfigIni($configPath);
87+
} else {
88+
$config = include $configPath;
89+
90+
if (is_array($config)) {
91+
$config = new Config($config);
92+
}
93+
}
94+
95+
} else {
96+
$config = $this->path->getConfig();
97+
}
98+
7799
$modelBuilder = new ModelBuilder(
78100
[
79101
'name' => $name,
80102
'schema' => $this->getOption('schema'),
103+
'config' => $config,
81104
'className' => $className,
82105
'fileName' => Text::uncamelize($className),
83106
'genSettersGetters' => $this->isReceivedOption('get-set'),

scripts/Phalcon/Migrations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ public static function getCurrentVersion($options)
498498

499499
if ($version = trim($version) ?: null) {
500500
$version = preg_split('/\r\n|\r|\n/', $version, -1, PREG_SPLIT_NO_EMPTY);
501+
natsort($version);
501502
$version = array_pop($version);
502503
}
503504

scripts/Phalcon/Mvc/Model/Migration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use Phalcon\Db\Adapter\Pdo\MysqlExtended as AdapterMysqlExtended;
3838
use Phalcon\Db\Dialect\PostgresqlExtended;
3939
use Phalcon\Db\Adapter\Pdo\PostgresqlExtended as AdapterPostgresqlExtended;
40+
use Phalcon\Utils\Nullify;
4041

4142
/**
4243
* Phalcon\Mvc\Model\Migration
@@ -860,7 +861,8 @@ function ($value) {
860861
$line
861862
);
862863

863-
self::$_connection->insert($tableName, $values, $fields);
864+
$nullify = new Nullify();
865+
self::$_connection->insert($tableName, $nullify($values), $fields);
864866
unset($line);
865867
}
866868
fclose($batchHandler);

scripts/Phalcon/Utils/Nullify.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
+------------------------------------------------------------------------+
5+
| Phalcon Developer Tools |
6+
+------------------------------------------------------------------------+
7+
| Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com) |
8+
+------------------------------------------------------------------------+
9+
| This source file is subject to the New BSD License that is bundled |
10+
| with this package in the file LICENSE.txt. |
11+
| |
12+
| If you did not receive a copy of the license and are unable to |
13+
| obtain it through the world-wide-web, please send an email |
14+
| to [email protected] so we can send you a copy immediately. |
15+
+------------------------------------------------------------------------+
16+
| Authors: Sergii Svyrydenko <[email protected]> |
17+
+------------------------------------------------------------------------+
18+
*/
19+
20+
namespace Phalcon\Utils;
21+
22+
class Nullify
23+
{
24+
public function __invoke($values)
25+
{
26+
$vals = array_map(
27+
function ($value) {
28+
if (function_exists('mb_strtolower')){
29+
return mb_strtolower($value);
30+
}
31+
},
32+
$values
33+
);
34+
35+
foreach ($vals as $key => $value) {
36+
if ($value == 'null'){
37+
$values[$key] = null;
38+
}
39+
}
40+
41+
return $values;
42+
}
43+
}

tests/_bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"TEST_DB_POSTGRESQL_HOST" => '127.0.0.1',
4646
"TEST_DB_POSTGRESQL_PORT" => 5432,
4747
"TEST_DB_POSTGRESQL_USER" => 'postgres',
48-
"TEST_DB_POSTGRESQL_PASSWD" => 'secret',
48+
"TEST_DB_POSTGRESQL_PASSWD" => '',
4949
"TEST_DB_POSTGRESQL_NAME" => 'devtools',
5050
"TEST_DB_POSTGRESQL_SCHEMA" => 'public',
5151
];
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Phalcon\Config;
4+
use Phalcon\Logger;
5+
6+
return new Config([
7+
'database' => [
8+
'adapter' => 'Postgresql',
9+
'host' => env('TEST_DB_POSTGRESQL_HOST', '127.0.0.1'),
10+
'username' => env('TEST_DB_POSTGRESQL_USER', 'postgres'),
11+
'password' => env('TEST_DB_POSTGRESQL_PASSWD', ''),
12+
'dbname' => env('TEST_DB_POSTGRESQL_NAME', 'devtools'),
13+
'schema' => env('TEST_DB_POSTGRESQL_SCHEMA', 'public')
14+
],
15+
'logger' => [
16+
'path' => tests_path('_output/logs/console/postgresql/'),
17+
'format' => '%date% [%type%] %message%',
18+
'date' => 'D j H:i:s',
19+
'logLevel' => Logger::DEBUG,
20+
'filename' => 'tests.log',
21+
]
22+
]);

tests/_data/console/app/test_insert_delete/migrations/1.0.0/test_insert_delete.dat

Whitespace-only changes.

0 commit comments

Comments
 (0)