public function search() { $offset_start = (int) $this->request->get('offset_start'); $offset_start = $offset_start < 0 ? 0 : $offset_start; $results_quantity = (int) $this->request->get('per_page'); $results_quantity = $results_quantity < 10 || $results_quantity > 50 ? 20 : $results_quantity; $this->query_parms = ['inactives' => $this->request->get('inactives'), 'like_field' => $this->request->get('like_field'), 'like_value' => $this->request->get('like_value'), 'sbas_id' => $this->request->get('sbas_id'), 'base_id' => $this->request->get('base_id'), 'last_model' => $this->request->get('last_model'), 'srt' => $this->request->get("srt", \User_Query::SORT_CREATIONDATE), 'ord' => $this->request->get("ord", \User_Query::ORD_DESC), 'per_page' => $results_quantity, 'offset_start' => $offset_start]; $query = new \User_Query($this->app); if (is_array($this->query_parms['base_id'])) { $query->on_base_ids($this->query_parms['base_id']); } elseif (is_array($this->query_parms['sbas_id'])) { $query->on_sbas_ids($this->query_parms['sbas_id']); } $this->results = $query->sort_by($this->query_parms["srt"], $this->query_parms["ord"])->like($this->query_parms['like_field'], $this->query_parms['like_value'])->last_model_is($this->query_parms['last_model'])->get_inactives($this->query_parms['inactives'])->include_templates(true)->on_bases_where_i_am($this->app['acl']->get($this->app['authentication']->getUser()), ['canadmin'])->limit($offset_start, $results_quantity)->execute(); if (null === ($invite = $this->app['manipulator.user']->getRepository()->findByLogin(User::USER_GUEST))) { $invite = $this->app['manipulator.user']->createUser(User::USER_GUEST, User::USER_GUEST); } if (null == ($autoregister = $this->app['manipulator.user']->getRepository()->findByLogin(User::USER_AUTOREGISTER))) { $autoregister = $this->app['manipulator.user']->createUser(User::USER_AUTOREGISTER, User::USER_AUTOREGISTER); } foreach ($this->query_parms as $k => $v) { if (is_null($v)) { $this->query_parms[$k] = false; } } $query = new \User_Query($this->app); $templates = $query->only_templates(true)->execute()->get_results(); return ['users' => $this->results, 'parm' => $this->query_parms, 'invite_user' => $invite, 'autoregister_user' => $autoregister, 'templates' => $templates]; }
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; }