/**
  * Given a name, get the custom field data model.  Attempts to retrieve from cache, if it is not available,
  * will attempt to retrieve from persistent storage, cache the model, and return.
  * @param string $name
  * @return CustomFieldData model
  * @throws NotFoundException
  */
 public static function getByName($name, $shouldCache = true)
 {
     if (isset(self::$cachedModelsByName[$name])) {
         return self::$cachedModelsByName[$name];
     }
     try {
         // not using default value to save cpu cycles on requests that follow the first exception.
         return GeneralCache::getEntry('CustomFieldData' . $name);
     } catch (NotFoundException $e) {
         assert('is_string($name)');
         assert('$name != ""');
         $bean = ZurmoRedBean::findOne('customfielddata', "name = :name ", array(':name' => $name));
         assert('$bean === false || $bean instanceof RedBean_OODBBean');
         if ($bean === false) {
             $customFieldData = new CustomFieldData();
             $customFieldData->name = $name;
             $customFieldData->serializedData = serialize(array());
             // An unused custom field data does not present as needing saving.
             $customFieldData->setNotModified();
         } else {
             $customFieldData = self::makeModel($bean);
         }
         if ($shouldCache) {
             self::$cachedModelsByName[$name] = $customFieldData;
             GeneralCache::cacheEntry('CustomFieldData' . $name, $customFieldData);
         }
         return $customFieldData;
     }
 }
Exemplo n.º 2
0
 /**
  * Given a name, get the custom field data model.  Attempts to retrieve from cache, if it is not available,
  * will attempt to retrieve from persistent storage, cache the model, and return.
  * @param string $name
  */
 public static function getByName($name)
 {
     try {
         return GeneralCache::getEntry('CustomFieldData' . $name);
     } catch (NotFoundException $e) {
         assert('is_string($name)');
         assert('$name != ""');
         $bean = R::findOne('customfielddata', "name = '{$name}'");
         assert('$bean === false || $bean instanceof RedBean_OODBBean');
         if ($bean === false) {
             $customFieldData = new CustomFieldData();
             $customFieldData->name = $name;
             $customFieldData->serializedData = serialize(array());
             // An unused custom field data does not present as needing saving.
             $customFieldData->setNotModified();
             return $customFieldData;
         }
         $model = self::makeModel($bean);
         GeneralCache::cacheEntry('CustomFieldData' . $name, $model);
         return $model;
     }
 }