Beispiel #1
0
 /**
  * Returns users with duplicated emails
  *
  * @return array An array of User
  */
 public function getWrongEmailUsers()
 {
     if (version_compare($this->appbox->get_version(), '3.9', '>=')) {
         return [];
     }
     $builder = $this->appbox->get_connection()->createQueryBuilder();
     /** @var Statement $stmt */
     $stmt = $builder->select('u.usr_mail', 'u.usr_id', 'u.last_conn', 'u.usr_login')->from($this->table, 'u')->where($builder->expr()->isNotNull('u.usr_mail'))->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $users = [];
     foreach ($rs as $row) {
         if (!isset($users[$row['usr_mail']])) {
             $users[$row['usr_mail']] = [];
         }
         $users[$row['usr_mail']][] = $row;
     }
     $badUsers = [];
     foreach ($users as $email => $usrs) {
         if (count($usrs) > 1) {
             $badUsers[$email] = [];
             foreach ($usrs as $usrInfo) {
                 $badUsers[$email][$usrInfo['usr_id']] = $usrInfo;
             }
         }
     }
     unset($users);
     return $badUsers;
 }
 public function __construct(\appbox $appbox)
 {
     $this->setName('Databoxes structure');
     foreach ($appbox->get_databoxes() as $databox) {
         foreach ($databox->get_meta_structure() as $field) {
             $this->verifyDataboxField($databox->get_dbname(), $field->get_name(), $field->get_original_source(), $field->get_tag()->getTagname());
         }
     }
 }
Beispiel #3
0
 public static function create(appbox $appbox, $type, array $data)
 {
     $sql = 'INSERT INTO api_webhooks (id, `type`, `data`, created)
         VALUES (null, :type, :data, NOW())';
     $stmt = $appbox->get_connection()->prepare($sql);
     $stmt->execute(['type' => $type, 'data' => json_encode($data)]);
     $stmt->closeCursor();
     return new API_Webhook($appbox, $appbox->get_connection()->lastInsertId());
 }
 /**
  *
  * @param  string $key
  * @return string
  */
 public function delete($key)
 {
     $return_value = $this->get($key);
     $sql = 'DELETE FROM bridge_account_settings
         WHERE account_id = :account_id AND `key` = :key';
     $params = [':account_id' => $this->account->get_id(), ':key' => $key];
     $stmt = $this->appbox->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     return $return_value;
 }
 /**
  * Resets rights for a user.
  *
  * @param User $user
  */
 private function doResetAdminRights(User $user)
 {
     $acl = $this->ACLProvider->get($user);
     $databoxes = $this->appbox->get_databoxes();
     $acl->give_access_to_sbas(array_map(function (\databox $databox) {
         return $databox->get_sbas_id();
     }, $databoxes));
     foreach ($databoxes as $databox) {
         $this->doResetAdminRightsOnDatabox($acl, $databox);
     }
 }
 public function __construct(\appbox $appbox)
 {
     $this->setName('Subdefs Paths');
     foreach ($appbox->get_databoxes() as $databox) {
         $this->ensureWriteableSubdefsPath($databox->get_dbname(), 'document', (string) $databox->get_sxml_structure()->path);
         foreach ($databox->get_subdef_structure() as $group => $subdefs) {
             foreach ($subdefs as $subdef) {
                 $this->ensureWriteableSubdefsPath($databox->get_dbname(), $group . '/' . $subdef->get_name(), (string) $databox->get_sxml_structure()->path);
             }
         }
     }
 }
 public function getAction(Request $request, $sbas_id, $record_id, $subdef)
 {
     $databox = $this->appbox->get_databox((int) $sbas_id);
     $record = new \record_adapter($this->app, $sbas_id, $record_id);
     $stamp = $watermark = false;
     if ($subdef != 'thumbnail') {
         $all_access = false;
         $subdefStruct = $databox->get_subdef_structure();
         if ($subdefStruct->getSubdefGroup($record->get_type())) {
             foreach ($subdefStruct->getSubdefGroup($record->get_type()) as $subdefObj) {
                 /** @var \databox_subdef $subdefObj */
                 if ($subdefObj->get_name() == $subdef) {
                     if ($subdefObj->get_class() == 'thumbnail') {
                         $all_access = true;
                     }
                     break;
                 }
             }
         }
         if (!$record->has_subdef($subdef) || !$record->get_subdef($subdef)->is_physically_present()) {
             throw new NotFoundHttpException();
         }
         if (!$this->acl->get($this->authentication->getUser())->has_access_to_subdef($record, $subdef)) {
             throw new AccessDeniedHttpException(sprintf('User has not access to subdef %s', $subdef));
         }
         $stamp = false;
         $watermark = !$this->acl->get($this->authentication->getUser())->has_right_on_base($record->get_base_id(), 'nowatermark');
         if ($watermark && !$all_access) {
             $subdef_class = null;
             try {
                 $subdef_class = $databox->get_subdef_structure()->get_subdef($record->get_type(), $subdef)->get_class();
             } catch (\Exception_Databox_SubdefNotFound $e) {
             }
             if ($subdef_class == \databox_subdef::CLASS_PREVIEW && $this->acl->get($this->authentication->getUser())->has_preview_grant($record)) {
                 $watermark = false;
             } elseif ($subdef_class == \databox_subdef::CLASS_DOCUMENT && $this->acl->get($this->authentication->getUser())->has_hd_grant($record)) {
                 $watermark = false;
             }
         }
         if ($watermark && !$all_access) {
             $repository = $this->app['repo.basket-elements'];
             $ValidationByRecord = $repository->findReceivedValidationElementsByRecord($record, $this->authentication->getUser());
             $ReceptionByRecord = $repository->findReceivedElementsByRecord($record, $this->authentication->getUser());
             if ($ValidationByRecord && count($ValidationByRecord) > 0) {
                 $watermark = false;
             } elseif ($ReceptionByRecord && count($ReceptionByRecord) > 0) {
                 $watermark = false;
             }
         }
     }
     return $this->deliverContent($request, $record, $subdef, $watermark, $stamp);
 }
 private function extractPath(\appbox $appbox)
 {
     $paths = [];
     foreach ($appbox->get_databoxes() as $databox) {
         $paths[] = (string) $databox->get_sxml_structure()->path;
         foreach ($databox->get_subdef_structure() as $group => $subdefs) {
             foreach ($subdefs as $subdef) {
                 $paths[] = $subdef->get_path();
             }
         }
     }
     return array_filter(array_unique($paths));
 }
 private function extractPath(\appbox $appbox)
 {
     $paths = [];
     foreach ($appbox->get_databoxes() as $databox) {
         foreach ($databox->get_subdef_structure() as $group => $subdefs) {
             if ('video' !== $group) {
                 continue;
             }
             foreach ($subdefs as $subdef) {
                 $paths[] = $subdef->get_path();
             }
         }
     }
     return array_filter(array_unique($paths));
 }
Beispiel #10
0
 public function __construct(Application $app, $force = false)
 {
     if ($force) {
         self::remove_lock_file();
     }
     if (self::lock_exists()) {
         throw new Exception_Setup_UpgradeAlreadyStarted('The upgrade is already started');
     }
     $this->appbox = $app['phraseanet.appbox'];
     if (version_compare($this->appbox->get_version(), '3.9', '<') && count(MailChecker::getWrongEmailUsers($app)) > 0) {
         throw new \Exception_Setup_FixBadEmailAddresses('Please fix the database before starting');
     }
     $this->write_lock();
     return $this;
 }
Beispiel #11
0
 private function updateDataboxPrefs(\appbox $appbox)
 {
     foreach ($appbox->get_databoxes() as $databox) {
         $sql = 'SELECT id, locale FROM pref WHERE prop = "ToU"';
         $stmt = $databox->get_connection()->prepare($sql);
         $stmt->execute();
         $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         $sql = 'UPDATE pref SET locale = :locale WHERE id = :id';
         $stmt = $databox->get_connection()->prepare($sql);
         foreach ($rows as $row) {
             $stmt->execute([':locale' => $this->extractLocale($row['locale']), ':id' => $row['id']]);
         }
         $stmt->closeCursor();
     }
 }
Beispiel #12
0
 /**
  *
  * @return Void
  */
 public function delete()
 {
     $sql = 'DELETE FROM bridge_elements WHERE id = :id';
     $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute([':id' => $this->id]);
     $stmt->closeCursor();
     return;
 }
Beispiel #13
0
 public static function deleteInsertedRow(\appbox $appbox, \API_OAuth2_Application $app)
 {
     $conn = $appbox->get_connection();
     $sql = '
   DELETE FROM api_applications
   WHERE application_id = :id
 ';
     $t = [':id' => $app->get_id()];
     $stmt = $conn->prepare($sql);
     $stmt->execute($t);
     $sql = '
   DELETE FROM api_accounts
   WHERE api_account_id  = :id
 ';
     $acc = self::getAccount();
     $t = [':id' => $acc->get_id()];
     $stmt = $conn->prepare($sql);
     $stmt->execute($t);
 }
 /**
  * Gets information about registration configuration and registration status if a user id is provided.
  *
  * @param null|user $user
  *
  * @return array
  */
 public function getRegistrationSummary(User $user = null)
 {
     $data = $userData = [];
     // Gets user data
     if (null !== $user) {
         $userData = $this->repository->getRegistrationsSummaryForUser($user);
     }
     foreach ($this->appbox->get_databoxes() as $databox) {
         $data[$databox->get_sbas_id()] = ['registrations' => ['by-type' => ['inactive' => [], 'accepted' => [], 'in-time' => [], 'out-dated' => [], 'pending' => [], 'rejected' => []]], 'config' => ['db-name' => $databox->get_dbname(), 'cgu' => $databox->get_cgus(), 'can-register' => $databox->isRegistrationEnabled(), 'collections' => []]];
         foreach ($databox->get_collections() as $collection) {
             // Sets collection info
             $data[$databox->get_sbas_id()]['config']['collections'][$collection->get_base_id()] = $this->getCollectionSummary($collection, $userData);
             // Sets registration by type
             if (null !== ($registration = $this->getUserCollectionRegistration($collection, $userData))) {
                 $data[$databox->get_sbas_id()]['registrations']['by-type'][$registration['type']][] = $registration;
             }
         }
     }
     return $data;
 }
 /**
  * @param array $selectedCollections
  * @return array
  */
 private function getAuthorizedCollections(array $selectedCollections = null)
 {
     $inscriptions = $this->registrationManager->getRegistrationSummary();
     $authorizedCollections = [];
     foreach ($this->appbox->get_databoxes() as $databox) {
         foreach ($databox->get_collections() as $collection) {
             if (null !== $selectedCollections && !in_array($collection->get_base_id(), $selectedCollections)) {
                 continue;
             }
             if ($canRegister = \igorw\get_in($inscriptions, [$databox->get_sbas_id(), 'config', 'collections', $collection->get_base_id(), 'can-register'])) {
                 $authorizedCollections[$collection->get_base_id()] = $canRegister;
             }
         }
     }
     return $authorizedCollections;
 }
Beispiel #16
0
 /**
  *
  * @param  appbox             $appbox
  * @param  API_OAuth2_Account $account
  * @param  string             $scope
  * @return API_OAuth2_Token
  */
 public static function create(appbox $appbox, API_OAuth2_Account $account, $scope = null)
 {
     $sql = 'INSERT INTO api_oauth_tokens
         (oauth_token, session_id, api_account_id, expires, scope)
         VALUES (:token, null, :account_id, :expire, :scope)';
     $expires = new \DateTime('+1 hour');
     $params = [':token' => self::generate_token(), ':account_id' => $account->get_id(), ':expire' => $expires->format(DATE_ISO8601), ':scope' => $scope];
     $stmt = $appbox->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     return new API_OAuth2_Token($appbox, $account);
 }
 /**
  * @param int $databoxId
  * @return \databox
  */
 private function getDatabox($databoxId)
 {
     return $this->appbox->get_databox((int) $databoxId);
 }
Beispiel #18
0
 protected function get_feed(Application $app, appbox $appbox, User $user, $pub_restrict, $homelink)
 {
     $user_key = 'user_' . $user->getId();
     if ($homelink == '1') {
         $feed_key = 'feed_homelink';
     } elseif ($pub_restrict == '1') {
         $feed_key = 'feed_restricted';
     } else {
         $feed_key = 'feed_public';
     }
     if (!array_key_exists($user_key, self::$feeds) || !isset(self::$feeds[$user_key][$feed_key])) {
         if ($homelink == '1') {
             $title = $user->getDisplayName() . ' - ' . 'homelink Feed';
         } elseif ($pub_restrict == '1') {
             $title = $user->getDisplayName() . ' - ' . 'private Feed';
         } else {
             $title = $user->getDisplayName() . ' - ' . 'public Feed';
         }
         $feed = new Feed();
         $publisher = new FeedPublisher();
         $feed->setTitle('title');
         $feed->setSubtitle('');
         $feed->addPublisher($publisher);
         $publisher->setFeed($feed);
         $publisher->setIsOwner(true);
         $publisher->setUser($user);
         if ($homelink) {
             $feed->setIsPublic(true);
             $app['orm.em']->persist($feed);
             $app['orm.em']->persist($user);
             $app['orm.em']->flush();
         } elseif ($pub_restrict == 1) {
             $collections = $app->getAclForUser($user)->get_granted_base();
             $collection = array_shift($collections);
             if (!$collection instanceof collection) {
                 foreach ($appbox->get_databoxes() as $databox) {
                     foreach ($databox->get_collections() as $coll) {
                         $collection = $coll;
                         break;
                     }
                     if ($collection instanceof collection) {
                         break;
                     }
                 }
             }
             if (!$collection instanceof collection) {
                 return false;
             }
             $feed->setCollection($collection);
         }
         self::$feeds[$user_key][$feed_key] = $feed;
     } else {
         $feed = self::$feeds[$user_key][$feed_key];
     }
     return $feed;
 }
<?php

require_once __DIR__ . '/../../vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;
$console = new Application('Functionnal tests for dailymotion API');
$console->register('upload:dailymotion')->setDescription('Test upload on dailymotion API')->setCode(function (InputInterface $input, OutputInterface $output) use($core) {
    try {
        $configuration = Yaml::parse(__DIR__ . '/config/keys.conf.yml');
    } catch (\Exception $e) {
        $output->writeln('<error>could not parse configuration file</error>');
        return;
    }
    $appbox = \appbox::get_instance($core);
    $found = false;
    foreach ($appbox->get_databoxes() as $databox) {
        /* @var $databox \databox */
        $sql = 'SELECT record_id FROM record WHERE type="video" AND (
                mime="video/mp4" OR mime="video/quicktime" OR mime="video/x-msvideo" OR mime="video/x-msvideo"
            )  LIMIT 1';
        $stmt = $databox->get_connection()->prepare($sql);
        $stmt->execute();
        $rows = $stmt->fetch(\PDO::FETCH_ASSOC);
        if (1 === count($rows)) {
            $found = true;
            $record = $databox->get_record($rows['record_id']);
            break;
        }
        unset($stmt);
Beispiel #20
0
 public static function reset_sbasDatas(appbox $appbox)
 {
     self::$_sbas_names = self::$_sbas_labels = self::$_sbas_params = self::$_bas2sbas = null;
     $appbox->delete_data_from_cache([self::CACHE_SBAS_NAMES, self::CACHE_SBAS_LABELS, self::CACHE_SBAS_FROM_BAS, self::CACHE_SBAS_PARAMS]);
     return;
 }
Beispiel #21
0
 /**
  * Index the records flagged as "to_index" on all databoxes
  *
  * @param BulkOperation $bulk
  */
 public function indexScheduled(BulkOperation $bulk)
 {
     foreach ($this->appbox->get_databoxes() as $databox) {
         $this->indexScheduledInDatabox($bulk, $databox);
     }
 }
Beispiel #22
0
 public function testItCanFetchDataboxById()
 {
     $databox = $this->getMockBuilder(\databox::class)->disableOriginalConstructor()->getMock();
     $this->appbox->expects($this->once())->method('get_databox')->with(42)->willReturn($databox);
     $this->assertSame($databox, $this->sut->findDataboxById(42));
 }
Beispiel #23
0
 public static function create(Application $app, databox $databox, appbox $appbox, $name, User $user = null)
 {
     $sbas_id = $databox->get_sbas_id();
     $connbas = $databox->get_connection();
     $conn = $appbox->get_connection();
     $new_bas = false;
     $prefs = '<?xml version="1.0" encoding="UTF-8"?>
         <baseprefs>
             <status>0</status>
             <sugestedValues>
             </sugestedValues>
         </baseprefs>';
     $sql = "INSERT INTO coll (coll_id, asciiname, prefs, logo)\n                VALUES (null, :name, :prefs, '')";
     $params = [':name' => $name, 'prefs' => $prefs];
     $stmt = $connbas->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $new_id = (int) $connbas->lastInsertId();
     $sql = "INSERT INTO bas (base_id, active, ord, server_coll_id, sbas_id, aliases)\n            VALUES\n            (null, 1, :ord, :server_coll_id, :sbas_id, '')";
     $stmt = $conn->prepare($sql);
     $stmt->execute([':server_coll_id' => $new_id, ':sbas_id' => $sbas_id, ':ord' => self::getNewOrder($conn, $sbas_id)]);
     $stmt->closeCursor();
     $new_bas = $conn->lastInsertId();
     $databox->delete_data_from_cache(databox::CACHE_COLLECTIONS);
     $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
     cache_databox::update($app, $sbas_id, 'structure');
     phrasea::reset_baseDatas($appbox);
     $collection = self::get_from_coll_id($app, $databox, $new_id);
     if (null !== $user) {
         $collection->set_admin($new_bas, $user);
     }
     return $collection;
 }
 private function getFlagsRules(\appbox $appbox, \ACL $acl, array $collections)
 {
     $rules = [];
     foreach ($collections as $collectionId) {
         $databoxId = \phrasea::sbasFromBas($this->app, $collectionId);
         $databox = $appbox->get_databox($databoxId);
         $mask_xor = $acl->get_mask_xor($collectionId);
         $mask_and = $acl->get_mask_and($collectionId);
         foreach ($databox->getStatusStructure()->getBits() as $bit) {
             $rules[$databoxId][$collectionId][$bit] = $this->computeAccess($mask_xor, $mask_and, $bit);
         }
     }
     return $rules;
 }