public function run() { $path = $this->options['dir'] . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . $this->options['name'] . '.sql'; if (!file_exists($path)) { throw new RuntimeException('The specified sql doesn\'t exist.'); } $db = $this->getDatabaseManager()->getDatabase('doctrine'); $this->conn = $db->getDoctrineConnection(); $this->conn->beginTransaction(); $this->conn->execute('SET FOREIGN_KEY_CHECKS = 0'); // for mysql $sql = opToolkit::unifyEOLCharacter($this->parseSql($path)); $queries = explode("\n", $sql); try { $this->executeQueries($queries); $this->conn->commit(); } catch (Exception $e) { $this->conn->rollback(); $this->conn->execute('SET FOREIGN_KEY_CHECKS = 0'); // for mysql throw $e; } $this->conn->execute('SET FOREIGN_KEY_CHECKS = 0'); // for mysql }
public function validate($validator, $value, $arguments = array()) { $value = opToolkit::unifyEOLCharacter($value); $list = array_map('trim', explode("\n", $value)); $list = array_unique($list); foreach ($list as $item) { if (!preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $item)) { throw new sfValidatorError($validator, 'invalid'); } } return implode("\n", $list); }
public function validate($validator, $values, $arguments = array()) { $values = $values + array('pc' => array(), 'mobile' => array(), 'invalid' => array()); $inputList = explode("\n", opToolkit::unifyEOLCharacter($values['mail_address'])); $inputList = array_unique(array_map('trim', $inputList)); foreach ($inputList as $value) { try { $result = parent::validate($validator, array('mail_address' => $value)); if (!empty($result['pc_address'])) { $values['pc'][] = $result['pc_address']; } elseif (!empty($result['mobile_address'])) { $values['mobile'][] = $result['mobile_address']; } } catch (sfValidatorError $e) { $values['invalid'][] = $value; } } if (empty($values['pc']) && empty($values['mobile'])) { throw new sfValidatorError($validator, 'All of the inputted E-mail addresses are invalid.'); } return $values; }