Skip to content

Commit

Permalink
Merge pull request phalcon#1102 from phalcon/3.2.x
Browse files Browse the repository at this point in the history
3.2.5
  • Loading branch information
sergeyklay authored Sep 11, 2017
2 parents 04ccd74 + 114b87b commit 3088ebf
Show file tree
Hide file tree
Showing 39 changed files with 1,929 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ env:
- TEST_DB_POSTGRESQL_USER="postgres"
- TEST_DB_POSTGRESQL_PASSWD=""
- TEST_DB_POSTGRESQL_NAME="devtools"
- TEST_DB_POSTGRESQL_SCHEMA="public"
- TEST_DB_MYSQL_DSN="mysql:host=127.0.0.1;dbname=devtools"
- TEST_DB_MYSQL_HOST="127.0.0.1"
- TEST_DB_MYSQL_PORT="3306"
Expand Down
7 changes: 6 additions & 1 deletion scripts/Phalcon/Builder/AllModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public function build()

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

$config = $this->getConfig();
if (gettype($this->options->get('config')) == 'object') {
$config = $this->options->get('config');
} else {
$config = $this->getConfig();
}

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

$modelBuilder = new Model([
'name' => $name,
'config' => $config,
'schema' => $schema,
'extends' => $this->options->get('extends'),
'namespace' => $this->options->get('namespace'),
Expand Down
6 changes: 5 additions & 1 deletion scripts/Phalcon/Builder/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ public function build()
$this->path->setRootPath($this->options->get('directory'));
}

$config = $this->getConfig();
if (gettype($this->options->get('config')) == 'object') {
$config = $this->options->get('config');
} else {
$config = $this->getConfig();
}

if (!$modelsDir = $this->options->get('modelsDir')) {
if (!$config->get('application') || !isset($config->get('application')->modelsDir)) {
Expand Down
23 changes: 23 additions & 0 deletions scripts/Phalcon/Commands/Builtin/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getPossibleParams()
return [
'name=s' => 'Table name',
'schema=s' => 'Name of the schema [optional]',
'config=s' => 'Configuration file [optional]',
'namespace=s' => "Model's namespace [optional]",
'get-set' => 'Attributes will be protected and have setters/getters [optional]',
'extends=s' => 'Model extends the class name supplied [optional]',
Expand Down Expand Up @@ -74,10 +75,32 @@ public function run(array $parameters)
$name = $this->getOption(['name', 1]);
$className = Utils::camelize(isset($parameters[1]) ? $parameters[1] : $name, '_-');

if ($this->isReceivedOption('config')) {
if (false == $this->path->isAbsolutePath($this->getOption('config'))) {
$configPath = $this->path->getRootPath() . $this->getOption('config');
} else {
$configPath = $this->getOption('config');
}

if (preg_match('/.*(:?\.ini)(?:\s)?$/i', $configPath)) {
$config = new ConfigIni($configPath);
} else {
$config = include $configPath;

if (is_array($config)) {
$config = new Config($config);
}
}

} else {
$config = $this->path->getConfig();
}

$modelBuilder = new ModelBuilder(
[
'name' => $name,
'schema' => $this->getOption('schema'),
'config' => $config,
'className' => $className,
'fileName' => Text::uncamelize($className),
'genSettersGetters' => $this->isReceivedOption('get-set'),
Expand Down
1 change: 1 addition & 0 deletions scripts/Phalcon/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ public static function getCurrentVersion($options)

if ($version = trim($version) ?: null) {
$version = preg_split('/\r\n|\r|\n/', $version, -1, PREG_SPLIT_NO_EMPTY);
natsort($version);
$version = array_pop($version);
}

Expand Down
4 changes: 3 additions & 1 deletion scripts/Phalcon/Mvc/Model/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Phalcon\Db\Adapter\Pdo\MysqlExtended as AdapterMysqlExtended;
use Phalcon\Db\Dialect\PostgresqlExtended;
use Phalcon\Db\Adapter\Pdo\PostgresqlExtended as AdapterPostgresqlExtended;
use Phalcon\Utils\Nullify;

/**
* Phalcon\Mvc\Model\Migration
Expand Down Expand Up @@ -860,7 +861,8 @@ function ($value) {
$line
);

self::$_connection->insert($tableName, $values, $fields);
$nullify = new Nullify();
self::$_connection->insert($tableName, $nullify($values), $fields);
unset($line);
}
fclose($batchHandler);
Expand Down
43 changes: 43 additions & 0 deletions scripts/Phalcon/Utils/Nullify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Developer Tools |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to [email protected] so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Sergii Svyrydenko <[email protected]> |
+------------------------------------------------------------------------+
*/

namespace Phalcon\Utils;

class Nullify
{
public function __invoke($values)
{
$vals = array_map(
function ($value) {
if (function_exists('mb_strtolower')){
return mb_strtolower($value);
}
},
$values
);

foreach ($vals as $key => $value) {
if ($value == 'null'){
$values[$key] = null;
}
}

return $values;
}
}
2 changes: 1 addition & 1 deletion tests/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"TEST_DB_POSTGRESQL_HOST" => '127.0.0.1',
"TEST_DB_POSTGRESQL_PORT" => 5432,
"TEST_DB_POSTGRESQL_USER" => 'postgres',
"TEST_DB_POSTGRESQL_PASSWD" => 'secret',
"TEST_DB_POSTGRESQL_PASSWD" => '',
"TEST_DB_POSTGRESQL_NAME" => 'devtools',
"TEST_DB_POSTGRESQL_SCHEMA" => 'public',
];
Expand Down
22 changes: 22 additions & 0 deletions tests/_data/console/app/postgresql/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Phalcon\Config;
use Phalcon\Logger;

return new Config([
'database' => [
'adapter' => 'Postgresql',
'host' => env('TEST_DB_POSTGRESQL_HOST', '127.0.0.1'),
'username' => env('TEST_DB_POSTGRESQL_USER', 'postgres'),
'password' => env('TEST_DB_POSTGRESQL_PASSWD', ''),
'dbname' => env('TEST_DB_POSTGRESQL_NAME', 'devtools'),
'schema' => env('TEST_DB_POSTGRESQL_SCHEMA', 'public')
],
'logger' => [
'path' => tests_path('_output/logs/console/postgresql/'),
'format' => '%date% [%type%] %message%',
'date' => 'D j H:i:s',
'logLevel' => Logger::DEBUG,
'filename' => 'tests.log',
]
]);
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

use Phalcon\Db\Column;
use Phalcon\Db\Index;
use Phalcon\Db\Reference;
use Phalcon\Mvc\Model\Migration;

/**
* Class TestInsertDeleteMigration_100
*/
class TestInsertDeleteMigration_100 extends Migration
{
/**
* Define the table structure
*
* @return void
*/
public function morph()
{
$this->morphTable('test_insert_delete', [
'columns' => [
new Column(
'id',
[
'type' => Column::TYPE_INTEGER,
'notNull' => true,
'autoIncrement' => true,
'first' => true
]
),
new Column(
'login_type_id',
[
'type' => Column::TYPE_INTEGER,
'notNull' => true,
'after' => 'id'
]
),
new Column(
'username',
[
'type' => Column::TYPE_VARCHAR,
'notNull' => true,
'size' => 255,
'after' => 'login_type_id'
]
),
new Column(
'name',
[
'type' => Column::TYPE_VARCHAR,
'notNull' => true,
'size' => 255,
'after' => 'username'
]
),
new Column(
'email_addr',
[
'type' => Column::TYPE_VARCHAR,
'notNull' => true,
'size' => 255,
'after' => 'name'
]
),
new Column(
'password',
[
'type' => Column::TYPE_VARCHAR,
'notNull' => true,
'size' => 255,
'after' => 'email_addr'
]
),
new Column(
'phone_num',
[
'type' => Column::TYPE_BIGINTEGER,
'after' => 'password'
]
),
new Column(
'token_id',
[
'type' => Column::TYPE_BIGINTEGER,
'after' => 'phone_num'
]
)
],
]
);
}

/**
* Run the migrations
*
* @return void
*/
public function up()
{
$this->batchInsert('test_insert_delete', [
'id',
'login_type_id',
'username',
'name',
'email_addr',
'password',
'phone_num',
'token_id'
]
);
}

/**
* Reverse the migrations
*
* @return void
*/
public function down()
{
$this->batchDelete('test_insert_delete');
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1,1,superadmin1,"First name Last name",[email protected],,1,NULL
Loading

0 comments on commit 3088ebf

Please sign in to comment.