Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.6.9 fixed for php7 by CrossKnowledge #1048

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 7.1

env:
- DB=mysql DB_USER=root

matrix:
allow_failures:
- php: 5.5

before_script:
# MySQL
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS test; DROP SCHEMA IF EXISTS second_hand_books; DROP SCHEMA IF EXISTS contest; DROP DATABASE IF EXISTS reverse_bookstore; DROP SCHEMA IF EXISTS bookstore_schemas; SET FOREIGN_KEY_CHECKS = 1;'; fi"
Expand Down
13 changes: 10 additions & 3 deletions generator/lib/task/PropelMigrationDownTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public function main()

$migration = $manager->getMigrationObject($nextMigrationTimestamp);
if (false === $migration->preDown($manager)) {
$this->log('preDown() returned false. Aborting migration.', Project::MSG_ERR);
$this->log(sprintf(
'[%s] preDown() returned false. Aborting migration.',
$manager->getMigrationClassName($nextMigrationTimestamp)
));

return false;
}
Expand All @@ -71,7 +74,11 @@ public function main()
$stmt->execute();
$res++;
} catch (PDOException $e) {
$this->log(sprintf('Failed to execute SQL "%s"', $statement), Project::MSG_ERR);
$this->log(sprintf(
'[%s] Failed to execute SQL "%s"',
$manager->getMigrationClassName($nextMigrationTimestamp),
$statement
));
// continue
}
}
Expand All @@ -81,7 +88,7 @@ public function main()
'Please review the code in "%s"',
$manager->getMigrationDir() . DIRECTORY_SEPARATOR . $manager->getMigrationClassName($nextMigrationTimestamp)
));
$this->log('Migration aborted', Project::MSG_ERR);
$this->log('Migration aborted');

return false;
}
Expand Down
13 changes: 10 additions & 3 deletions generator/lib/task/PropelMigrationTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public function main()
));
$migration = $manager->getMigrationObject($timestamp);
if (false === $migration->preUp($manager)) {
$this->log('preUp() returned false. Aborting migration.', Project::MSG_ERR);
$this->log(sprintf(
'[%s] preUp() returned false. Aborting migration.',
$manager->getMigrationClassName($timestamp)
));

return false;
}
Expand All @@ -67,7 +70,11 @@ public function main()
$stmt->execute();
$res++;
} catch (PDOException $e) {
$this->log(sprintf('Failed to execute SQL "%s"', $statement), Project::MSG_ERR);
$this->log(sprintf(
'[%s] Failed to execute SQL "%s"',
$manager->getMigrationClassName($timestamp),
$statement
));
// continue
}
}
Expand All @@ -77,7 +84,7 @@ public function main()
'Please review the code in "%s"',
$manager->getMigrationDir() . DIRECTORY_SEPARATOR . $manager->getMigrationClassName($timestamp)
));
$this->log('Migration aborted', Project::MSG_ERR);
$this->log('Migration aborted');

return false;
}
Expand Down
13 changes: 10 additions & 3 deletions generator/lib/task/PropelMigrationUpTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public function main()

$migration = $manager->getMigrationObject($nextMigrationTimestamp);
if (false === $migration->preUp($manager)) {
$this->log('preUp() returned false. Aborting migration.', Project::MSG_ERR);
$this->log(sprintf(
'[%s] preUp() returned false. Aborting migration.',
$manager->getMigrationClassName($nextMigrationTimestamp)
));

return false;
}
Expand All @@ -63,7 +66,11 @@ public function main()
$stmt->execute();
$res++;
} catch (PDOException $e) {
$this->log(sprintf('Failed to execute SQL "%s". Aborting migration.', $statement), Project::MSG_ERR);
$this->log(sprintf(
'[%s] Failed to execute SQL "%s"',
$manager->getMigrationClassName($nextMigrationTimestamp),
$statement
));

return false;
// continue
Expand All @@ -75,7 +82,7 @@ public function main()
'Please review the code in "%s"',
$manager->getMigrationDir() . DIRECTORY_SEPARATOR . $manager->getMigrationClassName($nextMigrationTimestamp)
));
$this->log('Migration aborted', Project::MSG_ERR);
$this->log('Migration aborted');

return false;
}
Expand Down
43 changes: 43 additions & 0 deletions generator/lib/util/AbstractPropelMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* Class AbstractPropelMigration
*/
abstract class AbstractPropelMigration implements IPropelMigration
{
/**
* @param PropelMigrationManager $manager
* @return bool
*/
public function preUp(PropelMigrationManager $manager)
{
return true;
}

/**
* @param PropelMigrationManager $manager
* @return bool
*/
public function postUp(PropelMigrationManager $manager)
{
return true;
}

/**
* @param PropelMigrationManager $manager
* @return bool
*/
public function preDown(PropelMigrationManager $manager)
{
return true;
}

/**
* @param PropelMigrationManager $manager
* @return bool
*/
public function postDown(PropelMigrationManager $manager)
{
return true;
}
}
47 changes: 47 additions & 0 deletions generator/lib/util/IPropelMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* Interface IPropelMigration
*/
interface IPropelMigration
{
/**
* @param PropelMigrationManager $manager
* @return bool
*/
public function preUp(PropelMigrationManager $manager);

/**
* @param PropelMigrationManager $manager
* @return bool
*/
public function postUp(PropelMigrationManager $manager);

/**
* @param PropelMigrationManager $manager
* @return bool
*/
public function preDown(PropelMigrationManager $manager);

/**
* @param PropelMigrationManager $manager
* @return bool
*/
public function postDown(PropelMigrationManager $manager);

/**
* Get the SQL statements for the Up migration
*
* @return array list of the SQL strings to execute for the Up migration
* the keys being the datasources
*/
public function getUpSQL();

/**
* Get the SQL statements for the Down migration
*
* @return array list of the SQL strings to execute for the Down migration
* the keys being the datasources
*/
public function getDownSQL();
}
26 changes: 2 additions & 24 deletions generator/lib/util/PropelMigrationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,31 +303,10 @@ public function getMigrationClassBody($migrationsUp, $migrationsDown, $timestamp
/**
* Data object containing the SQL and PHP code to migrate the database
* up to version $timestamp.
* Generated on $timeInWords $migrationAuthor
* Auto generated on $timeInWords $migrationAuthor
*/
class $migrationClassName
class $migrationClassName extends AbstractPropelMigration
{

public function preUp(\$manager)
{
// add the pre-migration code here
}

public function postUp(\$manager)
{
// add the post-migration code here
}

public function preDown(\$manager)
{
// add the pre-migration code here
}

public function postDown(\$manager)
{
// add the post-migration code here
}

/**
* Get the SQL statements for the Up migration
*
Expand All @@ -349,7 +328,6 @@ public function getDownSQL()
{
return $migrationDownString;
}

}
EOP;

Expand Down
3 changes: 3 additions & 0 deletions runtime/lib/adapter/DBMySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public function useQuoteIdentifier()
*/
public function applyLimit(&$sql, $offset, $limit)
{
$offset = (int) $offset;
$limit = (int) $limit;

if ($limit > 0) {
$sql .= " LIMIT " . ($offset > 0 ? $offset . ", " : "") . $limit;
} elseif ($offset > 0) {
Expand Down
18 changes: 10 additions & 8 deletions runtime/lib/formatter/PropelArrayFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ class PropelArrayFormatter extends PropelFormatter
public function format(PDOStatement $stmt)
{
$this->checkInit();
if ($class = $this->collectionName) {
$collection = new $class();
$collection->setModel($this->class);
$collection->setFormatter($this);
} else {
$collection = array();
}
$collection = array();

if ($this->isWithOneToMany() && $this->hasLimit) {
throw new PropelException('Cannot use limit() in conjunction with with() on a one-to-many relationship. Please remove the with() call, or the limit() call.');
}
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
if ($object = &$this->getStructuredArrayFromRow($row)) {
$collection[] = $object;
$collection[] =& $object;
}
}

if ($class = $this->collectionName) {
$collection = new $class($collection);
$collection->setModel($this->class);
$collection->setFormatter($this);
}

$this->currentObjects = array();
$this->alreadyHydratedObjects = array();
$stmt->closeCursor();
Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/parser/yaml/sfYamlInline.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected static function dumpArray($value)
if (
(1 == count($keys) && '0' == $keys[0])
||
(count($keys) > 1 && array_reduce($keys, create_function('$v,$w', 'return (integer) $v + $w;'), 0) == count($keys) * (count($keys) - 1) / 2))
(count($keys) > 1 && array_reduce($keys, create_function('$v,$w', 'return (integer) $v + (integer) $w;'), 0) == count($keys) * (count($keys) - 1) / 2))
{
$output = array();
foreach ($value as $val) {
Expand Down
6 changes: 2 additions & 4 deletions runtime/lib/query/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,7 @@ public function isSingleRecord()
*/
public function setLimit($limit)
{
// TODO: do we enforce int here? 32bit issue if we do
$this->limit = $limit;
$this->limit = (int) $limit;

return $this;
}
Expand All @@ -1197,8 +1196,7 @@ public function getLimit()
/**
* Set offset.
*
* @param int $offset An int with the value for offset. (Note this values is
* cast to a 32bit integer and may result in truncatation)
* @param int $offset An int with the value for offset.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function setOffset($offset)
Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/query/ModelCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public function offset($offset)
*/
public function select($columnArray)
{
if (!count($columnArray) || $columnArray == '') {
if (empty($columnArray)) {
throw new PropelException('You must ask for at least one column');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
require_once dirname(__FILE__) . '/../../../../generator/lib/model/Behavior.php';
require_once dirname(__FILE__) . '/../../../../generator/lib/behavior/AlternativeCodingStandardsBehavior.php';

use PHPUnit\Framework\TestCase;

/**
* Tests for TimestampableBehavior class
*
* @author François Zaninotto
* @version $Revision$
* @package generator.behavior
*/
class AlternativeCodingStandardsBehaviorTest extends PHPUnit_Framework_TestCase
class AlternativeCodingStandardsBehaviorTest extends TestCase
{
public function convertBracketsNewlineDataProvider()
{
Expand Down
4 changes: 3 additions & 1 deletion test/testsuite/generator/behavior/DelegateBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
require_once dirname(__FILE__) . '/../../../../generator/lib/behavior/DelegateBehavior.php';
require_once dirname(__FILE__) . '/../../../../runtime/lib/Propel.php';

use PHPUnit\Framework\TestCase;

/**
* Tests for DelegateBehavior class
*
* @author François Zaninotto
* @version $Revision$
* @package generator.behavior
*/
class DelegateBehaviorTest extends PHPUnit_Framework_TestCase
class DelegateBehaviorTest extends TestCase
{

public function setUp()
Expand Down
4 changes: 3 additions & 1 deletion test/testsuite/generator/behavior/NamespacedBehaviorTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
require_once __DIR__.'/../../../fixtures/generator/behavior/Foobar.php';

class NamespacedBehaviorTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class NamespacedBehaviorTest extends TestCase
{
/**
* test if issue 425 is resolved
Expand Down
Loading