<commit_before><?php

/**
 * new account validator.
 *
 * @package    Registry
 * @subpackage user
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: myNewAccountValidator.class.php 2 2006-04-03 21:07:20Z jphipps $
 */
class myNewAccountValidator extends sfValidator
{
  /**
   * Execute this validator.
   *
   * @param mixed A file or parameter value/array.
   * @param error An error message reference.
   *
   * @return bool true, if this validator executes successfully, otherwise
   *              false.
   */
  public function execute (&$value, &$error)
  {
    $this->getContext()->getRequest()->setAttribute('newaccount', true);

    $login = $value;

    $c = new Criteria();
    $c->add(UserPeer::NICKNAME, $login);
    $user = UserPeer::doSelectOne($c);

    // nickname exists?
    if ($user)
    {
      $error = $this->getParameterHolder()->get('newaccount_error');
      return false;
    }

    return true;
  }

  public function initialize ($context, $parameters = null)
  {
    // initialize parent
    parent::initialize($context);

    // set defaults
    $this->setParameter('unique_error', 'Uniqueness error');

    $this->getParameterHolder()->add($parameters);

    return true;
  }
}

<commit_msg>make sure we always have an agent admin<commit_after><?php

/**
 * new account validator.
 *
 * @package    Registry
 * @subpackage user
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: myNewAccountValidator.class.php 2 2006-04-03 21:07:20Z jphipps $
 */
class myAgentAdminValidator extends sfValidator
{
  /**
   * Execute this validator.
   *
   * @param mixed $value A file or parameter value/array.
   * @param error $error An error message reference.
   *
   * @return bool true, if this validator executes successfully, otherwise
   *              false.
   */
  public function execute (&$value, &$error)
  {
    $this->getContext()->getRequest()->setAttribute('newaccount', true);

    $agent_id = $this->getParameter('agent_id');

    $c = new Criteria();
    $c->add(AgentHasUserPeer::AGENT_ID, $agent_id);
    $c->add(AgentHasUserPeer::IS_ADMIN_FOR, true);
    $adminCount = AgentHasUserPeer::doCount($c);

    // there are still admins if this is set to false?
    if ($value == false && $adminCount <= 1)
    {
      $error = $this->getParameterHolder()->get('limit_error');
      return false;
    }

    return true;
  }

  public function initialize ($context, $parameters = null)
  {
    // initialize parent
    parent::initialize($context);

    // set defaults
    $this->setParameter('limit_error', 'There must be at least one');

    $this->getParameterHolder()->add($parameters);

    return true;
  }
}


{'fraction_non_alphanumeric': 0.1432320959880015, 'fraction_numerical': 0.011623547056617924, 'mean_word_length': 3.079510703363914, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 29, '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': '6809061', 'n_tokens_mistral': 849, 'n_tokens_neox': 805, 'n_words': 210}