Skip to content
Open
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
namespace PortlandLabs\Concrete5\MigrationTool\Publisher\Block;

use Concrete\Core\Database\Connection\Connection;
use Concrete\Core\Legacy\BlockRecord;
use Concrete\Core\Support\Facade\Application;
use Doctrine\DBAL\Types\Type;
use PortlandLabs\Concrete5\MigrationTool\Entity\Import\Batch;
use PortlandLabs\Concrete5\MigrationTool\Entity\Import\BlockValue\BlockValue;
use Concrete\Core\Page\Page;
Expand Down Expand Up @@ -35,13 +38,30 @@ public function publish(Batch $batch, $bt, Page $page, $area, BlockValue $value)
}
// Now we import the OTHER records.
if ($b) {
$app = Application::getFacadeApplication();
/** @var Connection $connection */
$connection = $app->make(Connection::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a hard dependency of this class instead of relying on the service locator? IE:

protected $db;

public function __construct(Connection $db)
{
    $this->db = $db;
}

$sm = $connection->getSchemaManager();
foreach ($records as $record) {
if (strcasecmp($record->getTable(), $bt->getController()->getBlockTypeDatabaseTable()) != 0) {
$columns = $sm->listTableColumns($record->getTable());
$aar = new BlockRecord($record->getTable());
$aar->bID = $b->getBlockID();
foreach ($record->getData() as $key => $value) {
$result = $inspector->inspect($value);
$aar->{$key} = $result->getReplacedValue();
$value = $result->getReplacedValue();
foreach ($columns as $column) {
if ($column->getName() === $key) {
if ($column->getType()->getName() === Type::INTEGER) {
if ($column->getNotnull()) {
$value = (int) $value;
} else {
$value = $value === null ? null : (int) $value;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($column->getName() === $key) {
if ($column->getType()->getName() === Type::INTEGER) {
if ($column->getNotnull()) {
$value = (int) $value;
} else {
$value = $value === null ? null : (int) $value;
}
}
}
if (
$column->getName() !== $key ||
$column->getType()->getName() === Type::INTEGER
) {
continue;
}
$value = ($column->getNotNull() || $column !== null) : (int) $value : null;
break;

Using an early return (early continue) is more readable to me here, also worth breaking when the proper column is matched

}
$aar->{$key} = $value;
}
$aar->Save();
}
Expand Down