Esempio n. 1
0
 public function create(User $user, $sbasId, $title, array $data)
 {
     $preset = new Preset();
     $preset->setUser($user);
     $preset->setTitle($title);
     $preset->setData($data);
     $preset->setSbasId($sbasId);
     $this->om->persist($preset);
     $this->om->flush();
     return $preset;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     $sql = ' SELECT edit_preset_id, creation_date, title, xml, usr_id, sbas_id
              FROM edit_presets';
     $em = $app['orm.em'];
     $n = 0;
     $em->getEventManager()->removeEventSubscriber(new TimestampableListener());
     foreach ($app->getApplicationBox()->get_connection()->fetchAll($sql) as $row) {
         if (null === ($user = $this->loadUser($app['orm.em'], $row['usr_id']))) {
             continue;
         }
         $preset = new Preset();
         $preset->setUser($user);
         $preset->setSbasId($row['sbas_id']);
         $preset->setTitle($row['title']);
         $fields = [];
         if (false !== ($sx = @simplexml_load_string($row['xml']))) {
             if (false === isset($sx->fields)) {
                 continue;
             }
             foreach ($sx->fields->children() as $name => $value) {
                 $fields[] = ['name' => $name, 'value' => $value];
             }
         }
         $preset->setData($fields);
         $em->persist($preset);
         $n++;
         if ($n % 20 === 0) {
             $em->flush();
             $em->clear();
         }
     }
     $em->flush();
     $em->clear();
     $em->getEventManager()->addEventSubscriber(new TimestampableListener());
     return true;
 }