예제 #1
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return boolean
  */
 public function fire($event, $params, &$entry)
 {
     $params = ['entry_id' => $entry->getId(), 'notify_email' => $params['notify_email']];
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $entry_id = $dom_xml->createElement('entry_id');
     $entry_id->appendChild($dom_xml->createTextNode($params['entry_id']));
     $root->appendChild($entry_id);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $Query = new \User_Query($this->app);
     $Query->include_phantoms(true)->include_invite(false)->include_templates(false)->email_not_null(true);
     if ($entry->getFeed()->getCollection($this->app)) {
         $Query->on_base_ids([$entry->getFeed()->getCollection($this->app)->get_base_id()]);
     }
     $start = 0;
     $perLoop = 100;
     $from = ['email' => $entry->getAuthorEmail(), 'name' => $entry->getAuthorName()];
     do {
         $results = $Query->limit($start, $perLoop)->execute()->get_results();
         foreach ($results as $user_to_notif) {
             $mailed = false;
             if ($params['notify_email'] && $this->shouldSendNotificationFor($user_to_notif->getId())) {
                 $readyToSend = false;
                 try {
                     $token = $this->app['tokens']->getUrlToken(\random::TYPE_FEED_ENTRY, $user_to_notif->getId(), null, $entry->getId());
                     $url = $this->app->url('lightbox', ['LOG' => $token]);
                     $receiver = Receiver::fromUser($user_to_notif);
                     $readyToSend = true;
                 } catch (\Exception $e) {
                 }
                 if ($readyToSend) {
                     $mail = MailInfoNewPublication::create($this->app, $receiver);
                     $mail->setButtonUrl($url);
                     $mail->setAuthor($entry->getAuthorName());
                     $mail->setTitle($entry->getTitle());
                     $this->app['notification.deliverer']->deliver($mail);
                     $mailed = true;
                 }
             }
             $this->broker->notify($user_to_notif->getId(), __CLASS__, $datas, $mailed);
         }
         $start += $perLoop;
     } while (count($results) > 0);
     return true;
 }
예제 #2
0
 protected function doExecute(InputInterface $input, OutputInterface $output)
 {
     $databox = $this->container['phraseanet.appbox']->get_databox((int) $input->getArgument('databox_id'));
     $new_collection = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], $input->getArgument('collname'));
     if ($new_collection && $input->getOption('base_id_rights')) {
         $query = new \User_Query($this->container);
         $total = $query->on_base_ids([$input->getOption('base_id_rights')])->get_total();
         $n = 0;
         while ($n < $total) {
             $results = $query->limit($n, 40)->execute()->get_results();
             foreach ($results as $user) {
                 $this->container['acl']->get($user)->duplicate_right_from_bas($input->getOption('base_id_rights'), $new_collection->get_base_id());
             }
             $n += 40;
         }
     }
     $app = $this->container;
     $this->container['manipulator.acl']->resetAdminRights($this->container['manipulator.user']->getRepository()->findAdmins());
     $this->container['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($new_collection));
 }
예제 #3
0
 public function unmount_databox()
 {
     foreach ($this->get_collections() as $collection) {
         $collection->unmount_collection($this->app);
     }
     $query = new User_Query($this->app);
     $total = $query->on_sbas_ids([$this->id])->include_phantoms(false)->include_special_users(true)->include_invite(true)->include_templates(true)->get_total();
     $n = 0;
     while ($n < $total) {
         $results = $query->limit($n, 50)->execute()->get_results();
         foreach ($results as $user) {
             $this->app['acl']->get($user)->delete_data_from_cache(ACL::CACHE_RIGHTS_SBAS);
             $this->app['acl']->get($user)->delete_data_from_cache(ACL::CACHE_RIGHTS_BAS);
             $this->app['acl']->get($user)->delete_injected_rights_sbas($this);
         }
         $n += 50;
     }
     foreach ($this->app['EM']->getRepository('Phraseanet:StoryWZ')->findByDatabox($this->app, $this) as $story) {
         $this->app['EM']->remove($story);
     }
     foreach ($this->app['EM']->getRepository('Phraseanet:BasketElement')->findElementsByDatabox($this) as $element) {
         $this->app['EM']->remove($element);
     }
     $this->app['EM']->flush();
     $params = [':site_id' => $this->app['conf']->get(['main', 'key'])];
     $sql = 'DELETE FROM clients WHERE site_id = :site_id';
     $stmt = $this->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $sql = 'DELETE FROM memcached WHERE site_id = :site_id';
     $stmt = $this->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $sql = "DELETE FROM sbas WHERE sbas_id = :sbas_id";
     $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute([':sbas_id' => $this->id]);
     $stmt->closeCursor();
     $sql = "DELETE FROM sbasusr WHERE sbas_id = :sbas_id";
     $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute([':sbas_id' => $this->id]);
     $stmt->closeCursor();
     $this->app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
     return;
 }
예제 #4
0
 /**
  * Create a new collection
  *
  * @param  Application $app        The silex application
  * @param  Request     $request    The current HTTP request
  * @param  integer     $databox_id The requested databox
  * @return Response
  */
 public function createCollection(Application $app, Request $request, $databox_id)
 {
     if (($name = trim($request->request->get('name', ''))) === '') {
         return $app->redirectPath('admin_database_display_new_collection_form', ['databox_id' => $databox_id, 'error' => 'name']);
     }
     try {
         $databox = $app['phraseanet.appbox']->get_databox($databox_id);
         $collection = \collection::create($app, $databox, $app['phraseanet.appbox'], $name, $app['authentication']->getUser());
         if ($request->request->get('ccusrothercoll') === "on" && null !== ($othcollsel = $request->request->get('othcollsel'))) {
             $query = new \User_Query($app);
             $total = $query->on_base_ids([$othcollsel])->get_total();
             $n = 0;
             while ($n < $total) {
                 $results = $query->limit($n, 20)->execute()->get_results();
                 foreach ($results as $user) {
                     $app['acl']->get($user)->duplicate_right_from_bas($othcollsel, $collection->get_base_id());
                 }
                 $n += 20;
             }
         }
         $app['dispatcher']->dispatch(PhraseaEvents::COLLECTION_CREATE, new CollectionCreateEvent($collection));
         return $app->redirectPath('admin_display_collection', ['bas_id' => $collection->get_base_id(), 'success' => 1, 'reload-tree' => 1]);
     } catch (\Exception $e) {
         return $app->redirectPath('admin_database_submit_collection', ['databox_id' => $databox_id, 'error' => 'error']);
     }
 }
예제 #5
0
 public function unmount_collection(Application $app)
 {
     $params = [':base_id' => $this->get_base_id()];
     $query = new User_Query($app);
     $total = $query->on_base_ids([$this->get_base_id()])->include_phantoms(false)->include_special_users(true)->include_invite(true)->include_templates(true)->get_total();
     $n = 0;
     while ($n < $total) {
         $results = $query->limit($n, 50)->execute()->get_results();
         foreach ($results as $user) {
             $app['acl']->get($user)->delete_data_from_cache(ACL::CACHE_RIGHTS_SBAS);
             $app['acl']->get($user)->delete_data_from_cache(ACL::CACHE_RIGHTS_BAS);
         }
         $n += 50;
     }
     $sql = "DELETE FROM basusr WHERE base_id = :base_id";
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $sql = "DELETE FROM bas WHERE base_id = :base_id";
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $this->app['manipulator.registration']->deleteRegistrationsOnCollection($this);
     phrasea::reset_baseDatas($app['phraseanet.appbox']);
     return $this;
 }