Created
May 20, 2016 15:38
-
-
Save lamenezes/ceed81e0311860322496d59662fea621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Migrations; | |
use Doctrine\DBAL\Migrations\AbstractMigration; | |
use Doctrine\DBAL\Schema\Schema; | |
use Olist\Bundle\FreightBundle\Entity\Plp; | |
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* Auto-generated Migration: Please modify to your needs! | |
*/ | |
class Version20160519104119 extends AbstractMigration implements ContainerAwareInterface | |
{ | |
/** | |
* @param Schema $schema | |
*/ | |
private $container; | |
public function setContainer(ContainerInterface $container = null) | |
{ | |
$this->container = $container; | |
} | |
public function up(Schema $schema) | |
{ | |
$em = $this->container->get('doctrine.orm.entity_manager'); | |
$ordersRepository = $this->container->get('olist.order.repository'); | |
$filesRepository = $em->getRepository("\Olist\ApiBundle\Entity\File"); | |
// $filesRepository = $this->container->get('olist.file_entity_manager'); | |
$stmtOrdersAttr = $this->connection->prepare( | |
"SELECT DISTINCT orders_id | |
FROM order_attributes | |
WHERE attribute_key IN ('plp', 'plp-ticket', 'plp-reversa', 'plp-ticket-reversa')" | |
); | |
$stmtOrdersAttr->execute(); | |
$orders = $stmtOrdersAttr->fetchAll(); | |
$STATUS = Plp::STATUS_COMPLETED; | |
foreach($orders as $order) { | |
$order = $ordersRepository->findOneById(1229); | |
print_r($order->getId()); | |
// daqui para baixo pode estar (e está) errado | |
$plpFile = $filesRepository->findOneBy(['path' => $order->getAttribute('plp')]); | |
$shippingLabelFile = $filesRepository->findOneBy( | |
['path' => $order->getAttribute('plp-ticket')]); | |
// TODO: parse plp number from plp_file | |
$insert = "INSERT INTO plp(number, plp_file, shipping_label_file, created_at, | |
updated_at, status, reverse, seller_id) | |
VALUES (NULL, %d, %d, '%s', '%s', %d, %d, %d)"; | |
$insert = sprintf( | |
$insert, | |
$plpFile->getId(), | |
$shippingLabelFile->getId(), | |
$order->getAttribute('plp')['modified_at'], | |
$order->getAttribute('plp')['updated_at'], | |
$STATUS); | |
$this->addSql($insert); | |
$stmtPlpFile = $this->connection->prepare( | |
"SELECT f.id | |
FROM order_attributes as oa | |
JOIN files as f ON oa.attribute_value = f.path | |
WHERE attribute_key = 'plp'" | |
); | |
$this->oi(); | |
} | |
// insert into plp: plp_file, shipping_label_file, status, reverse?, seller_id | |
// insert into shipping_label: created_at, modified_at, order_id, tracking_code_id, file_id, plp_id | |
} | |
/** | |
* @param Schema $schema | |
*/ | |
public function down(Schema $schema) | |
{ | |
// this down() migration is auto-generated, please modify it to your needs | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment