Skip to content

Commit

Permalink
Dev Fixed some database related issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Sep 1, 2015
1 parent f57baee commit 99bde50
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 94 deletions.
4 changes: 2 additions & 2 deletions application/controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ public function sendRegistrationEmail($iSurveyId,$iTokenId){
$aMail['message'] = str_replace("@@{$key}URL@@", $url, $aMail['message']);
}
// Replace the fields
$aMail['subject']=ReplaceFields($aMail['subject'], $aReplacementFields);
$aMail['message']=ReplaceFields($aMail['message'], $aReplacementFields);
$aMail['subject']=\ls\helpers\Replacements::ReplaceFields($aMail['subject'], $aReplacementFields);
$aMail['message']=\ls\helpers\Replacements::ReplaceFields($aMail['message'], $aReplacementFields);
$sFrom = "{$aSurveyInfo['adminname']} <{$aSurveyInfo['adminemail']}>";
$sBounce=getBounceEmail($iSurveyId);
$sTo=$oToken->email;
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/TokensController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ protected function sendRegistrationEmail(\Token $token){
$aMail['message'] = str_replace("@@{$key}URL@@", $url, $aMail['message']);
}
// Replace the fields
$aMail['subject']=ReplaceFields($aMail['subject'], $aReplacementFields);
$aMail['message']=ReplaceFields($aMail['message'], $aReplacementFields);
$aMail['subject']=\ls\helpers\Replacements::ReplaceFields($aMail['subject'], $aReplacementFields);
$aMail['message']=\ls\helpers\Replacements::ReplaceFields($aMail['message'], $aReplacementFields);
$sFrom = "{$aSurveyInfo['adminname']} <{$aSurveyInfo['adminemail']}>";
$sBounce=getBounceEmail($iSurveyId);
$sTo=$token->email;
Expand Down
7 changes: 2 additions & 5 deletions application/core/db/MssqlSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

class MssqlSchema extends CMssqlSchema
{
use SmartColumnTypeTrait {
getColumnType as parentGetColumnType;
}
use SmartColumnTypeTrait;
public function __construct($conn) {
parent::__construct($conn);
/**
Expand All @@ -29,13 +27,12 @@ public function __construct($conn) {

public function getColumnType($type)
{
$result = $this->parseType($type, function($type) { return parent::getColumnType($type); });
/**
* @date 2015-5-11
* Bug occurs with DBLIB when specifying neither of NULL and NOT NULL.
* So if resulting type doesn't contain NULL then add it.
*/
$result = $this->parentGetColumnType($type);

if (stripos($result, 'NULL') === false) {
$result .= ' NULL';
}
Expand Down
2 changes: 1 addition & 1 deletion application/core/db/MysqlSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public function alterEngine($table, $engine) {
return true;
}

}
}
3 changes: 3 additions & 0 deletions application/core/db/PgsqlSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ public function createDatabase($name) {
}
return true;
}



}
67 changes: 41 additions & 26 deletions application/core/db/SmartColumnTypeTrait.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
<?php

trait SmartColumnTypeTrait {
trait SmartColumnTypeTrait
{

/**
* Adds support for replacing default arguments.
* @param string $type
* @return string
*/
public function getColumnType($type)
{
if (isset(Yii::app()->db->schema->columnTypes[$type]))
{ // Direct : get it
$sResult=Yii::app()->db->schema->columnTypes[$type];
* Splits a column type into 3 parts:
* - The base type.
* - Any parameters that must be passed between brackets (brackets are ommitted).
* - Any arguments that must be appended.
* @param string $type
*/
protected function splitColumnType($type) {
$regex = '/^([a-zA-Z ]+)\s*(\(.+\))?\s*(.*)$/';
if (preg_match($regex, $type, $matches)) {
return [
'base' => trim($matches[1]),
'arguments' => substr($matches[2], 1, -1),
'suffix' => $matches[3]
];
}
elseif (preg_match('/^([a-zA-Z ]+)\((.+?)\)(.*)$/', $type, $matches))
{ // With params : some test to do
$baseType = $this->getColumnType($matches[1]);
if(preg_match('/^([a-zA-Z ]+)\((.+?)\)(.*)$/', $baseType, $baseMatches))
{ // Replace the default Yii param
$sResult=preg_replace('/\(.+\)/', "(".$matches[2].")",parent::getColumnType($matches[1]." ".$matches[3]));
}
else
{ // Get the base type and join
$sResult=join(" ",array($baseType,"(".$matches[2].")",$matches[3]));
}
}
else
{
$sResult = $this->getColumnType($type);
throw new \Exception("Could not parse type.");
}

protected function parseType($type, callable $baseParser) {
$parts = $this->splitColumnType($type);
$base = $baseParser($parts['base']);
// vd($base);
$baseParts = $this->splitColumnType($base);
if (!empty($parts['arguments'])) {
$baseParts['arguments'] = $parts['arguments'];
}
return $sResult;

$result = $baseParts['base'] . (!empty($baseParts['arguments']) ? "({$baseParts['arguments']}) " : " ") . $parts['suffix'];
return $result;
}
/**
* Adds support for replacing default arguments.
* @param string $type
* @return string
*/
public function getColumnType($type)
{
// This is bad practice, it assumes knowledge about the traits' parent.
return $this->parseType($type, function($type) { return parent::getColumnType($type); });
}
}
40 changes: 20 additions & 20 deletions application/helpers/FrontEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public static function makegraph($step, $total)
}

/**
* checkUploadedFileValidity used in SurveyRuntimeHelper
* @todo Move this to UploadQuestion.
*/
function checkUploadedFileValidity($surveyid, $move, $backok = null)
private static function checkUploadedFileValidity($surveyid, $move, $backok = null)
{
return false;
$session = App()->surveySessionManager->current;
Expand Down Expand Up @@ -164,7 +164,7 @@ function checkUploadedFileValidity($surveyid, $move, $backok = null)
*
* @param mixed $quotaexit
*/
function submittokens($quotaexit = false)
public static function submittokens($quotaexit = false)
{
$session = App()->surveySessionManager->current;
$survey = $session->survey;
Expand Down Expand Up @@ -232,14 +232,14 @@ function submittokens($quotaexit = false)
$dateformatdatat = \ls\helpers\SurveyTranslator::getDateFormatData($survey->getLocalizedDateFormat());
$numberformatdatat = \ls\helpers\SurveyTranslator::getRadixPointData($survey->getLocalizedNumberFormat());
$redata = [];
$subject = \ls\helpers\Replacements::templatereplace($subject, $aReplacementVars, $redata, null);
$subject = Replacements::templatereplace($subject, $aReplacementVars, $redata, null);

$subject = html_entity_decode($subject, ENT_QUOTES);

$ishtml = $survey->bool_htmlemail;

$message = html_entity_decode(
\ls\helpers\Replacements::templatereplace($survey->getLocalizedConfirmationEmail(), $aReplacementVars, $redata, null),
Replacements::templatereplace($survey->getLocalizedConfirmationEmail(), $aReplacementVars, $redata, null),
ENT_QUOTES
);
if (!$ishtml) {
Expand Down Expand Up @@ -277,7 +277,7 @@ function submittokens($quotaexit = false)
/**
* Send a submit notification to the email address specified in the notifications tab in the survey settings
*/
function sendSubmitNotifications($surveyid)
public static function sendSubmitNotifications($surveyid)
{
// @todo: Remove globals
global $thissurvey, $maildebug, $tokensexist;
Expand Down Expand Up @@ -326,7 +326,7 @@ function sendSubmitNotifications($surveyid)

if (!empty($thissurvey['emailnotificationto'])) {
$aRecipient = explode(";",
ReplaceFields($thissurvey['emailnotificationto'], array('ADMINEMAIL' => $thissurvey['adminemail']),
Replacements::ReplaceFields($thissurvey['emailnotificationto'], array('ADMINEMAIL' => $thissurvey['adminemail']),
true));
foreach ($aRecipient as $sRecipient) {
$sRecipient = trim($sRecipient);
Expand All @@ -343,7 +343,7 @@ function sendSubmitNotifications($surveyid)
}
//Make an array of email addresses to send to
$aRecipient = explode(";",
ReplaceFields($thissurvey['emailresponseto'], array('ADMINEMAIL' => $thissurvey['adminemail']), true));
Replacements::ReplaceFields($thissurvey['emailresponseto'], array('ADMINEMAIL' => $thissurvey['adminemail']), true));
foreach ($aRecipient as $sRecipient) {
$sRecipient = trim($sRecipient);
if (validateEmailAddress($sRecipient)) {
Expand Down Expand Up @@ -399,8 +399,8 @@ function sendSubmitNotifications($surveyid)

$redata = compact(array_keys(get_defined_vars()));
if (count($aEmailNotificationTo) > 0) {
$sMessage = \ls\helpers\Replacements::templatereplace($thissurvey['email_admin_notification'], $aReplacementVars, $redata, null);
$sSubject = \ls\helpers\Replacements::templatereplace($thissurvey['email_admin_notification_subj'], $aReplacementVars, $redata, null);
$sMessage = Replacements::templatereplace($thissurvey['email_admin_notification'], $aReplacementVars, $redata, null);
$sSubject = Replacements::templatereplace($thissurvey['email_admin_notification_subj'], $aReplacementVars, $redata, null);
foreach ($aEmailNotificationTo as $sRecipient) {
if (!SendEmailMessage($sMessage, $sSubject, $sRecipient, $sFrom, $sitename, true,
getBounceEmail($surveyid), $aRelevantAttachments)
Expand All @@ -426,8 +426,8 @@ function sendSubmitNotifications($surveyid)
}
}
if (count($aEmailResponseTo) > 0) {
$sMessage = \ls\helpers\Replacements::templatereplace($thissurvey['email_admin_responses'], $aReplacementVars, $redata, null);
$sSubject = \ls\helpers\Replacements::templatereplace($thissurvey['email_admin_responses_subj'], $aReplacementVars, $redata, null);
$sMessage = Replacements::templatereplace($thissurvey['email_admin_responses'], $aReplacementVars, $redata, null);
$sSubject = Replacements::templatereplace($thissurvey['email_admin_responses_subj'], $aReplacementVars, $redata, null);
foreach ($aEmailResponseTo as $sRecipient) {
if (!SendEmailMessage($sMessage, $sSubject, $sRecipient, $sFrom, $sitename, true,
getBounceEmail($surveyid), $aRelevantAttachments)
Expand Down Expand Up @@ -524,7 +524,7 @@ public static function surveymover()
* @param mixed $surveyid
* @param mixed $returndataonly - only returns an array with data
*/
function doAssessment(Survey $survey, $returndataonly = false)
public static function doAssessment(Survey $survey, $returndataonly = false)
{
$session = App()->surveySessionManager->current;

Expand Down Expand Up @@ -662,7 +662,7 @@ function doAssessment(Survey $survey, $returndataonly = false)
* @param bool $return - set to true to return information, false do the quota
* @return array - nested array, Quotas->Members->Fields, includes quota information matched in session.
*/
function checkCompletedQuota($return = false)
public static function checkCompletedQuota($return = false)
{
bP();
static $aMatchedQuotas; // EM call 2 times quotas with 3 lines of php code, then use static.
Expand Down Expand Up @@ -726,7 +726,7 @@ function checkCompletedQuota($return = false)
$aSurveyInfo = getSurveyInfo($session->surveyId, $session->language);
$sTemplatePath = Template::getTemplatePath($aSurveyInfo['template']);
$sClientToken = isset($_SESSION['survey_' . $session->surveyId]['token']) ? $_SESSION['survey_' . $session->surveyId]['token'] : "";
// $redata for \ls\helpers\Replacements::templatereplace
// $redata for Replacements::templatereplace
$aDataReplacement = array(
'thissurvey' => $aSurveyInfo,
'clienttoken' => $sClientToken,
Expand Down Expand Up @@ -759,10 +759,10 @@ function checkCompletedQuota($return = false)
submittokens(true);
}
// Construct the default message
$sMessage = \ls\helpers\Replacements::templatereplace($sMessage, array(), $aDataReplacement, null);
$sUrl = passthruReplace($sUrl, $aSurveyInfo);
$sUrl = \ls\helpers\Replacements::templatereplace($sUrl, array(), $aDataReplacement, null);
$sUrlDescription = \ls\helpers\Replacements::templatereplace($sUrlDescription, array(), $aDataReplacement, null);
$sMessage = Replacements::templatereplace($sMessage, array(), $aDataReplacement, null);
$sUrl = Replacements::passthruReplace($sUrl, $aSurveyInfo);
$sUrl = Replacements::templatereplace($sUrl, array(), $aDataReplacement, null);
$sUrlDescription = Replacements::templatereplace($sUrlDescription, array(), $aDataReplacement, null);

// Construction of default message inside quotamessage class
$sHtmlQuotaMessage = "<div class='quotamessage limesurveycore'>\n";
Expand Down Expand Up @@ -813,7 +813,7 @@ function checkCompletedQuota($return = false)
* Resets all question timers by expiring the related cookie - this needs to be called before any output is done
* @todo Make cookie survey ID aware
*/
function resetTimers()
public static function resetTimers()
{
$cookie = new CHttpCookie('limesurvey_timers', '');
$cookie->expire = time() - 3600;
Expand Down
14 changes: 7 additions & 7 deletions application/helpers/Replacements.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ public static function templatereplace(

// Assessments
$assessmenthtml = "";
if (isset($surveyId) && !is_null($surveyId) && function_exists('doAssessment')) {
$assessmentdata = doAssessment($surveyId, true);
if (isset($surveyId) && !is_null($surveyId) && function_exists('\ls\helpers\FrontEnd::doAssessment')) {
$assessmentdata = \ls\helpers\FrontEnd::doAssessment($surveyId, true);
$_assessment_current_total = $assessmentdata['total'];
if (stripos($line, "{ASSESSMENTS}")) {
$assessmenthtml = doAssessment($surveyId, false);
$assessmenthtml = \ls\helpers\FrontEnd::doAssessment($surveyId, false);
}
} else {
$_assessment_current_total = '';
Expand Down Expand Up @@ -485,9 +485,9 @@ public static function templatereplace(
}


// This function replaces field names in a text with the related values
// (e.g. for email and template functions)
function ReplaceFields($text, $fieldsarray, $bReplaceInsertans = true, $staticReplace = true)
// This function replaces field names in a text with the related values
// (e.g. for email and template functions)
public static function ReplaceFields($text, $fieldsarray, $bReplaceInsertans = true, $staticReplace = true)
{

if ($bReplaceInsertans) {
Expand Down Expand Up @@ -515,7 +515,7 @@ function ReplaceFields($text, $fieldsarray, $bReplaceInsertans = true, $staticRe
* @return string This string is returned containing the substituted responses
*
*/
function PassthruReplace($line, Survey $survey)
public static function passthruReplace($line, Survey $survey)
{
while (strpos($line, "{PASSTHRU:") !== false) {
$p1 = strpos($line, "{PASSTHRU:"); // startposition
Expand Down

0 comments on commit 99bde50

Please sign in to comment.