Version20180221174411.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Application\Migrations;
  3. use Doctrine\DBAL\Migrations\AbstractMigration;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use MigrationsBundle\Migrations\MigrationsBase;
  6. /**
  7. * Auto-generated Migration: Please modify to your needs!
  8. */
  9. class Version20180221174411 extends MigrationsBase
  10. {
  11. /**
  12. * @param Schema $schema
  13. */
  14. public function up(Schema $schema)
  15. {
  16. $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
  17. if (!$schema->hasTable('service_port') == true) {
  18. $this->addSql('CREATE TABLE service_port (id INT AUTO_INCREMENT NOT NULL, olt_id BIGINT DEFAULT NULL, onu_id INT DEFAULT NULL, number INT DEFAULT 0 NOT NULL, gemport INT DEFAULT 0 NOT NULL, vlan INT DEFAULT 0 NOT NULL, INDEX IDX_8DD2E92069FFAD89 (olt_id), INDEX IDX_8DD2E920AB83998C (onu_id), UNIQUE INDEX sp_unique (olt_id, number), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
  19. $this->addSql('ALTER TABLE service_port ADD CONSTRAINT FK_8DD2E92069FFAD89 FOREIGN KEY (olt_id) REFERENCES olt (id)');
  20. $this->addSql('ALTER TABLE service_port ADD CONSTRAINT FK_8DD2E920AB83998C FOREIGN KEY (onu_id) REFERENCES onu (id)');
  21. $this->addSql('ALTER TABLE olt CHANGE execute_snmp execute_snmp BOOLEAN DEFAULT TRUE');
  22. $this->addSql('ALTER TABLE olt_audit CHANGE execute_snmp execute_snmp BOOLEAN DEFAULT TRUE');
  23. }
  24. $result = $this->connection->query("select o.id id, o.olt_id, nap_id, pon_serial_number, position, slot, link, ot.name FROM onu o JOIN nap n ON (n.id = o.nap_id) JOIN olt t ON (t.id = o.olt_id) JOIN oltmodel ot ON(t.model_id = ot.id) WHERE o.deleted_at IS NULL AND ot.name LIKE 'Huawei MA5608T';");
  25. $i = 0;
  26. $vlangemport_config = array('voip' => array('gemport' => 0, 'vlan' => 13), 'data' => array('gemport' => 1, 'vlan' => 10));
  27. while($rtr = $result->fetch()){
  28. $i++;
  29. $pon_serial_number = $rtr['pon_serial_number'];
  30. $slot = $rtr['slot'];
  31. $link = $rtr['link'];
  32. $position = $rtr['position'];
  33. $olt_id = $rtr['olt_id'];
  34. $onu_id = $rtr['id'];
  35. $service_port = array(
  36. //{% set service_port_data = "1" ~ slot ~ link ~ ("%02d" | format(onu)) %}
  37. "data" => "1" . $slot . $link . sprintf ("%02d", $position),
  38. //{% set service_port_voip = "2" ~ slot ~ link ~ ("%02d" | format(onu)) %}
  39. "voip" => "2" . $slot . $link . sprintf ("%02d", $position),
  40. );
  41. foreach($service_port as $type => $number){
  42. $gemport = $vlangemport_config[$type]['gemport'];
  43. $vlan = $vlangemport_config[$type]['vlan'];
  44. $sql = "REPLACE INTO service_port (olt_id, onu_id, number, gemport, vlan) VALUES ($olt_id, $onu_id, $number, $gemport, $vlan);";
  45. $this->addSql($sql);
  46. }
  47. }
  48. }
  49. /**
  50. * @param Schema $schema
  51. */
  52. public function down(Schema $schema)
  53. {
  54. // this down() migration is auto-generated, please modify it to your needs
  55. $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
  56. }
  57. }