<commit_before><?php

/**
 * Listener class for sfInlineObjectTemplate
 * 
 * @package     sfInlineObjectPlugin
 * @subpackage  behavior
 * @author      <NAME> <<EMAIL>>
 */

class sfInlineObjectContainerListener extends Doctrine_Record_Listener
{
  protected $_options = array();
  
  public function __construct(array $options)
  {
    $this->_options = $options;
  }

  /**
   * Clear the related inline objects on insert
   */
  public function postInsert(Doctrine_Event $event)
  {
    $this->_deleteInlineObjectReferences($event);
  }

  /**
   * Clear the related inline objects on update
   */
  public function postUpdate(Doctrine_Event $event)
  {
    $this->_deleteInlineObjectReferences($event);
  }

  /**
   * Removes all references to related objects that are as a result of
   * inline object references
   * 
   * This guarantees that if a reference to a related object is removed
   * from an inline text field, that relation won't continue to exist forever.
   * In that sense, this is effectively a "cache clear" for these relations.
   */
  protected function _deleteInlineObjectReferences(Doctrine_Event $event)
  {
    foreach ($this->_options['relations'] as $relation)
    {
      // Unlink ALL related objects on the given relation
      $event->getInvoker()->unlink($relation, array(), true);
    }
  }
}<commit_msg>Better error reporting if the schema for the Template is setup incorrectly.<commit_after><?php

/**
 * Listener class for sfInlineObjectTemplate
 * 
 * @package     sfInlineObjectPlugin
 * @subpackage  behavior
 * @author      <NAME> <<EMAIL>>
 */

class sfInlineObjectContainerListener extends Doctrine_Record_Listener
{
  protected $_options = array();
  
  public function __construct(array $options)
  {
    $this->_options = $options;
  }

  /**
   * Clear the related inline objects on insert
   */
  public function postInsert(Doctrine_Event $event)
  {
    $this->_deleteInlineObjectReferences($event);
  }

  /**
   * Clear the related inline objects on update
   */
  public function postUpdate(Doctrine_Event $event)
  {
    $this->_deleteInlineObjectReferences($event);
  }

  /**
   * Removes all references to related objects that are as a result of
   * inline object references
   * 
   * This guarantees that if a reference to a related object is removed
   * from an inline text field, that relation won't continue to exist forever.
   * In that sense, this is effectively a "cache clear" for these relations.
   */
  protected function _deleteInlineObjectReferences(Doctrine_Event $event)
  {
    $relations = $this->_options['relations'];
    
    if (!is_array($relations))
    {
      throw new sfException(sprintf('Invalid "relations" option on sfInlineObjectContainerTemplate - expects array. Given: "%s"', $relations));
    }
    
    foreach ($relations as $relation)
    {
      // Unlink ALL related objects on the given relation
      $event->getInvoker()->unlink($relation, array(), true);
    }
  }
}
{'fraction_non_alphanumeric': 0.09751176866173504, 'fraction_numerical': 0.0, 'mean_word_length': 3.473684210526316, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5324636', 'n_tokens_mistral': 825, 'n_tokens_neox': 810, 'n_words': 265}