private function recursive($foreign, &$order)
 {
     foreach ($foreign as $f) {
         $many = $this->store->getManager()->getConnection()->getSchemaManager()->listTableForeignKeys($f->getForeignTableName());
         if (count($many) > 0) {
             $this->recursive($many, $order);
             if (!isset($order[$f->getForeignTableName()])) {
                 $order[$f->getForeignTableName()] = $f->getForeignTableName();
             }
         } else {
             if (!isset($order[$f->getForeignTableName()])) {
                 $order[$f->getForeignTableName()] = $f->getForeignTableName();
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * 
  * Salva los datos con el nombre y ruta especificado
  * 
  * $this->getStore()
  *               ->getExporter()
  *               ->setEntities(array(
  *                   '\examples\exampleBundle\Model\Entity\Persona'
  *               ))
  *               ->save(__DIR__ . '/exportExample.php');
  * 
  * @param string $file nombre del archivo a salvar con los datos
  */
 public function save($file)
 {
     $definition = array();
     foreach ($this->entities as $entity) {
         $meta = $this->store->getManager()->getMetadataFactory()->getMetadataFor($entity);
         $table = $meta->getTableName();
         $association = $meta->associationMappings;
         foreach ($association as $map) {
             if (isset($map['joinTable']) and isset($map['joinTable']['name'])) {
                 $mapTable = $map['joinTable']['name'];
                 if (!isset($definition[$mapTable])) {
                     $resultmap = $this->store->getManager()->getConnection()->executeQuery("SELECT * FROM {$mapTable}");
                     $definition[$mapTable] = $resultmap->fetchAll(\PDO::FETCH_ASSOC);
                 }
             }
         }
         $result = $this->store->getManager()->getConnection()->executeQuery("SELECT * FROM {$table}");
         $definition[$table] = $result->fetchAll(\PDO::FETCH_ASSOC);
     }
     foreach ($this->tables as $table) {
         $result = $this->store->getManager()->getConnection()->executeQuery("SELECT * FROM {$table}");
         $definition[$table] = $result->fetchAll(\PDO::FETCH_ASSOC);
     }
     $time = date("F d Y h:i:s A");
     file_put_contents($file, "<?php\n /**\n  * THIS FILE IS GENERATED BY RAPTOR EXPORTER, TO EASLY UPLOAD THIS FILE AGAIN INTO THE \n  * DATABASE USE THE IMPORTER CLASS.\n  * \n  * Generated {$time}\n  */\n \n\$create=" . var_export($this->entities, true) . ";\n\$data=" . var_export($definition, true) . ";\n\n");
 }
Esempio n. 3
0
 /**
  * 
  * Importa los datos previamente salvados con el Exporter hacia la base de datos
  * Esta funcion retorna TRUE si la rutina fue realizada con exito, FALSE en caso contrario
  * 
  * $this->getStore()->getImporter()->createIfNotExist(true)->import(__DIR__.'/exportExample.php');
  * 
  * @param string $file el archivo a subir
  * @throws \Exception throws una excepcion cuando el archivo a subir no exista
  * @return boolean
  */
 public function import($file)
 {
     if (!file_exists($file)) {
         throw new \Exception("The file especified in the Importer does not exist");
     }
     include $file;
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->store->getManager());
     try {
         $meta = array();
         if ($this->create) {
             foreach ($create as $class) {
                 $meta[] = $this->store->getManager()->getMetadataFactory()->getMetadataFor($class);
             }
             //$schemaTool->createSchema($meta);
             $schemaTool->updateSchema($meta, true);
         }
     } catch (\Exception $exc) {
     }
     try {
         $this->store->getManager()->getConnection()->beginTransaction();
         $ord = new TableDependencyOrder(array_keys($data), $this->store);
         $dependency = $ord->getOrder();
         foreach ($dependency as $tableName) {
             $rows = $data[$tableName];
             //                if($clearTable)
             //                    $this->store->getManager()->getConnection()->executeQuery("DELETE FROM $tableName");
             foreach ($rows as $row) {
                 $this->store->getManager()->getConnection()->insert($tableName, $row);
             }
         }
         $this->store->getManager()->getConnection()->commit();
         return true;
     } catch (\Exception $exc) {
         $this->errors = $exc->getMessage();
         $this->store->getManager()->getConnection()->rollback();
         return false;
     }
 }