/**
  * Invalidate the persistence layer only after a succesful compile of the
  * LESS files.
  *
  * @param array $variables
  * @param boolean $update_persistence
  * @return boolean
  */
 public function invalidate_cache(array $variables = null, $update_persistence = false)
 {
     // Reset the parse time to force a browser reload of the CSS, whether we are
     // updating persistence or not.
     $this->save_less_parse_time();
     try {
         // Try to parse the css
         $css = $this->lessphp_controller->parse_less_files($variables);
         if ($update_persistence) {
             $this->update_persistence_layer($css);
         } else {
             $this->persistance_context->delete_data_from_persistence();
         }
     } catch (Ai1ec_Cache_Write_Exception $e) {
         $message = Ai1ec_Helper_Factory::create_admin_message_instance('<p>' . __("The LESS file compiled correctly but there was an error while saving the generated CSS to persistence.", AI1EC_PLUGIN_NAME) . '</p>', __("An error ocurred while updating CSS", AI1EC_PLUGIN_NAME));
         $this->admin_notices_helper->add_renderable_children($message);
         // this means a correct parsing but an error in saving to persistance
         return false;
     } catch (Exception $e) {
         $message = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf(__('<p>The message returned was: <em>%s</em></p>', AI1EC_PLUGIN_NAME), $e->getMessage()), __("An error occurred while compiling LESS files", AI1EC_PLUGIN_NAME));
         $this->admin_notices_helper->add_renderable_children($message);
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * Invalidate the persistence layer only after a successful compile of the
  * LESS files.
  *
  * @param  array   $variables          LESS variable array to use
  * @param  boolean $update_persistence Whether the persist successful compile
  *
  * @return boolean                     Whether successful
  */
 public function invalidate_cache(array $variables = null, $update_persistence = false)
 {
     // Reset the parse time to force a browser reload of the CSS, whether we are
     // updating persistence or not.
     $this->save_less_parse_time();
     $notification = $this->_registry->get('notification.admin');
     try {
         // Try to parse the css
         $css = $this->lessphp_controller->parse_less_files($variables);
         if ($update_persistence) {
             $this->update_persistence_layer($css);
         } else {
             $this->persistance_context->delete_data_from_persistence();
         }
     } catch (Ai1ec_Cache_Write_Exception $e) {
         // This means successful during parsing but problems persisting the CSS.
         $message = '<p>' . Ai1ec_I18n::__("The LESS file compiled correctly but there was an error while saving the generated CSS to persistence.") . '</p>';
         $notification->store($message, 'error');
         return false;
     } catch (Exception $e) {
         // An error from lessphp.
         $message = sprintf(Ai1ec_I18n::__('<p><strong>There was an error while compiling CSS.</strong> The message returned was: <em>%s</em></p>'), $e->getMessage());
         $notification->store($message, 'error', 1);
         return false;
     }
     return true;
 }