diff --git a/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php b/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php index fa9f4e5037..a9b210b850 100644 --- a/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php +++ b/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Command\Developer; use Alchemy\Phrasea\Border\Manager; use Alchemy\Phrasea\Command\Command; +use Alchemy\Phrasea\Media\SubdefSubstituer; use Alchemy\Phrasea\Model\Entities\ApiApplication; use Alchemy\Phrasea\Model\Entities\AuthFailure; use Alchemy\Phrasea\Model\Entities\AggregateToken; @@ -280,7 +281,9 @@ class RegenerateSqliteDb extends Command $DI['lazaret_1'] = $element; }; - $this->container['border-manager']->process($session, $file, $callback, Manager::FORCE_LAZARET); + /** @var Manager $borderManager */ + $borderManager = $this->container['border-manager']; + $borderManager->process($session, $file, $callback, Manager::FORCE_LAZARET); } private function generateUsers(EntityManager $em, \Pimple $DI) @@ -368,7 +371,8 @@ class RegenerateSqliteDb extends Command private function generateCollection(\Pimple $DI) { - $coll = $collection_no_acces = $collection_no_acces_by_status = $db = null; + $coll = $collection_no_acces = $collection_no_acces_by_status = null; + /** @var \databox[] $databoxes */ $databoxes = $this->container['phraseanet.appbox']->get_databoxes(); foreach ($databoxes as $databox) { @@ -390,16 +394,15 @@ class RegenerateSqliteDb extends Command } } - $DI['databox'] = $coll->get_databox(); + $DI['databox'] = $databox = $coll->get_databox(); $DI['coll'] = $coll; - - if (!$collection_no_acces instanceof collection) { + if (!$collection_no_acces instanceof \collection) { $collection_no_acces = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], 'COLL_TEST_NO_ACCESS', $DI['user']); } $DI['coll_no_access'] = $collection_no_acces; - if (!$collection_no_acces_by_status instanceof collection) { + if (!$collection_no_acces_by_status instanceof \collection) { $collection_no_acces_by_status = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], 'COLL_TEST_NO_ACCESS_BY_STATUS', $DI['user']); } @@ -420,8 +423,10 @@ class RegenerateSqliteDb extends Command foreach (range(1, 3) as $i) { $story = \record_adapter::createStory($this->container, $DI['coll']); if ($i < 3) { - $this->container['subdef.substituer']->substitute($story, 'preview', $media); - $this->container['subdef.substituer']->substitute($story, 'thumbnail', $media); + /** @var SubdefSubstituer $substituer */ + $substituer = $this->container['subdef.substituer']; + $substituer->substitute($story, 'preview', $media); + $substituer->substitute($story, 'thumbnail', $media); } $DI['record_story_' . $i] = $story; } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Structure.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Structure.php index a6fc9eab2f..2c2ee92024 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Structure.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Structure/Structure.php @@ -14,6 +14,10 @@ class Structure private $facets = array(); private $aliases = array(); + /** + * @param \databox[] $databoxes + * @return self + */ public static function createFromDataboxes(array $databoxes) { $structure = new self(); diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index a41834240f..c41e691613 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -822,8 +822,17 @@ class ACL implements cache_cacheableInterface } try { - $this->_global_rights = $this->get_data_from_cache(self::CACHE_GLOBAL_RIGHTS); - $this->_rights_sbas = $this->get_data_from_cache(self::CACHE_RIGHTS_SBAS); + $global_rights = $this->get_data_from_cache(self::CACHE_GLOBAL_RIGHTS); + if (!is_array($global_rights)) { + throw new Exception('global rights were not properly retrieved'); + } + $sbas_rights = $this->get_data_from_cache(self::CACHE_RIGHTS_SBAS); + if (!is_array($sbas_rights)) { + throw new Exception('sbas rights were not properly retrieved'); + } + + $this->_global_rights = $global_rights; + $this->_rights_sbas = $sbas_rights; return $this; } catch (\Exception $e) { @@ -880,9 +889,21 @@ class ACL implements cache_cacheableInterface } try { - $this->_global_rights = $this->get_data_from_cache(self::CACHE_GLOBAL_RIGHTS); - $this->_rights_bas = $this->get_data_from_cache(self::CACHE_RIGHTS_BAS); - $this->_limited = $this->get_data_from_cache(self::CACHE_LIMITS_BAS); + $data = $this->get_data_from_cache(self::CACHE_GLOBAL_RIGHTS); + if (!is_array($data)) { + throw new Exception('Unable to retrieve global rights'); + } + $this->_global_rights = $data; + $data = $this->get_data_from_cache(self::CACHE_RIGHTS_BAS); + if (!is_array($data)) { + throw new Exception('Unable to retrieve base rights'); + } + $this->_rights_bas = $data; + $data = $this->get_data_from_cache(self::CACHE_LIMITS_BAS); + if (!is_array($data)) { + throw new Exception('Unable to retrieve limits rights'); + } + $this->_limited = $data; return $this; } catch (\Exception $e) { diff --git a/lib/classes/appbox.php b/lib/classes/appbox.php index 9fcc61e52d..039c0845cf 100644 --- a/lib/classes/appbox.php +++ b/lib/classes/appbox.php @@ -371,7 +371,7 @@ class appbox extends base } $ret[$sbas_id] = $databox; } catch (NotFoundHttpException $e) { - $this->app['monolog']->error(sprintf('Databox %s is not reliable.', $databox->get_sbas_id())); + $this->app['monolog']->error(sprintf('Databox %s is not reliable.', $sbas_id)); } } @@ -383,7 +383,10 @@ class appbox extends base protected function retrieve_sbas_ids() { try { - return $this->get_data_from_cache(self::CACHE_SBAS_IDS); + $data = $this->get_data_from_cache(self::CACHE_SBAS_IDS); + if (is_array($data)) { + return $data; + } } catch (\Exception $e) { } diff --git a/lib/classes/collection.php b/lib/classes/collection.php index e7b26f48c1..77f93f6ae3 100644 --- a/lib/classes/collection.php +++ b/lib/classes/collection.php @@ -64,6 +64,9 @@ class collection implements cache_cacheableInterface { try { $datas = $this->get_data_from_cache(); + if (!is_array($datas)) { + throw new \Exception('Collection could not be retrieved from cache'); + } $this->is_active = $datas['is_active']; $this->base_id = $datas['base_id']; $this->available = $datas['available']; diff --git a/lib/classes/databox.php b/lib/classes/databox.php index 17918d526a..a06e33e398 100644 --- a/lib/classes/databox.php +++ b/lib/classes/databox.php @@ -230,7 +230,10 @@ class databox extends base protected function get_available_collections() { try { - return $this->get_data_from_cache(self::CACHE_COLLECTIONS); + $data = $this->get_data_from_cache(self::CACHE_COLLECTIONS); + if (is_array($data)) { + return $data; + } } catch (\Exception $e) { } @@ -551,13 +554,15 @@ class databox extends base , ':password' => $password ]; - $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); + /** @var appbox $appbox */ + $appbox = $app['phraseanet.appbox']; + $stmt = $appbox->get_connection()->prepare($sql); $stmt->execute($params); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($row) { - return $app['phraseanet.appbox']->get_databox((int) $row['sbas_id']); + return $appbox->get_databox((int) $row['sbas_id']); } try { @@ -576,7 +581,7 @@ class databox extends base $stmt->closeCursor(); $sql = 'SELECT MAX(ord) as ord FROM sbas'; - $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); + $stmt = $appbox->get_connection()->prepare($sql); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -588,10 +593,10 @@ class databox extends base $sql = 'INSERT INTO sbas (sbas_id, ord, host, port, dbname, sqlengine, user, pwd) VALUES (null, :ord, :host, :port, :dbname, "MYSQL", :user, :password)'; - $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); + $stmt = $appbox->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); - $sbas_id = (int) $app['phraseanet.appbox']->get_connection()->lastInsertId(); + $sbas_id = (int) $appbox->get_connection()->lastInsertId(); $app['orm.add']([ 'host' => $host, @@ -601,9 +606,9 @@ class databox extends base 'password' => $password ]); - $app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES); + $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); - $databox = $app['phraseanet.appbox']->get_databox($sbas_id); + $databox = $appbox->get_databox($sbas_id); $databox->insert_datas(); $databox->setNewStructure( @@ -688,15 +693,18 @@ class databox extends base */ public function get_meta_structure() { - $metaStructData = array(); - if ($this->meta_struct) { return $this->meta_struct; } try { $metaStructData = $this->get_data_from_cache(self::CACHE_META_STRUCT); + if (!is_array($metaStructData)) { + throw new Exception('Invalid metaStructData'); + } } catch (\Exception $e) { + $metaStructData = array(); + $sql = 'SELECT id, `name` FROM metadatas_structure ORDER BY sorter ASC'; $stmt = $this->get_connection()->prepare($sql); $stmt->execute(); @@ -711,7 +719,7 @@ class databox extends base $this->meta_struct = new databox_descriptionStructure(); - foreach ((array) $metaStructData as $row) { + foreach ($metaStructData as $row) { $this->meta_struct->add_element(databox_field::get_instance($this->app, $this, $row['id'])); } @@ -1219,7 +1227,10 @@ class databox extends base protected function retrieve_structure() { try { - return $this->get_data_from_cache(self::CACHE_STRUCTURE); + $data = $this->get_data_from_cache(self::CACHE_STRUCTURE); + if (is_array($data)) { + return $data; + } } catch (\Exception $e) { } diff --git a/lib/classes/databox/subdefsStructure.php b/lib/classes/databox/subdefsStructure.php index e2904f0863..60e8cc33b3 100644 --- a/lib/classes/databox/subdefsStructure.php +++ b/lib/classes/databox/subdefsStructure.php @@ -79,7 +79,7 @@ class databox_subdefsStructure implements IteratorAggregate, Countable { $sx_struct = $this->databox->get_sxml_structure(); - $this->AvSubdefs = [ + $avSubdefs = [ 'image' => [], 'video' => [], 'audio' => [], @@ -96,13 +96,14 @@ class databox_subdefsStructure implements IteratorAggregate, Countable foreach ($subdefgroup as $k => $subdefs) { $subdefgroup_name = strtolower($subdefs->attributes()->name); - if ( ! isset($AvSubdefs[$subdefgroup_name])) { - $AvSubdefs[$subdefgroup_name] = []; + if ( ! isset($avSubdefs[$subdefgroup_name])) { + $avSubdefs[$subdefgroup_name] = []; } foreach ($subdefs as $sd) { $subdef_name = strtolower($sd->attributes()->name); + $type = null; switch ($subdefgroup_name) { case 'audio': $type = new \Alchemy\Phrasea\Media\Type\Audio(); @@ -121,13 +122,12 @@ class databox_subdefsStructure implements IteratorAggregate, Countable break; default: continue; - break; } - $AvSubdefs[$subdefgroup_name][$subdef_name] = new databox_subdef($type, $sd, $this->translator); + $avSubdefs[$subdefgroup_name][$subdef_name] = new databox_subdef($type, $sd, $this->translator); } } - $this->AvSubdefs = $AvSubdefs; + $this->AvSubdefs = $avSubdefs; return $this; } diff --git a/lib/classes/media/subdef.php b/lib/classes/media/subdef.php index cab13bfe10..7264be71ae 100644 --- a/lib/classes/media/subdef.php +++ b/lib/classes/media/subdef.php @@ -160,6 +160,9 @@ class media_subdef extends media_abstract implements cache_cacheableInterface { try { $datas = $this->get_data_from_cache(); + if (!is_array($datas)) { + throw new \Exception('Could not retrieve data'); + } $this->mime = $datas['mime']; $this->width = $datas['width']; $this->height = $datas['height']; diff --git a/lib/classes/phrasea.php b/lib/classes/phrasea.php index 7384c259d1..db8e07dbc5 100644 --- a/lib/classes/phrasea.php +++ b/lib/classes/phrasea.php @@ -46,9 +46,12 @@ class phrasea } try { - self::$_sbas_params = $app['phraseanet.appbox']->get_data_from_cache(self::CACHE_SBAS_PARAMS); + $params = $app['phraseanet.appbox']->get_data_from_cache(self::CACHE_SBAS_PARAMS); + if (is_array($params)) { + self::$_sbas_params = $params; - return self::$_sbas_params; + return $params; + } } catch (\Exception $e) { } diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index d1c17baa27..d3c4f6bb52 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -93,6 +93,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface try { $datas = $this->get_data_from_cache(); + if (!is_array($datas)) { + throw new Exception('Could not retrieve record data'); + } + $this->mime = $datas['mime']; $this->sha256 = $datas['sha256']; $this->original_name = $datas['original_name']; @@ -105,7 +109,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return $this; } catch (\Exception $e) { - } $connbas = $this->databox->get_connection(); @@ -586,7 +589,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface protected function get_available_subdefs() { try { - return $this->get_data_from_cache(self::CACHE_SUBDEFS); + $data = $this->get_data_from_cache(self::CACHE_SUBDEFS); + if (is_array($data)) { + return $data; + } } catch (\Exception $e) { }