Permalink
Browse files

Merge branch 'release-3.3.4'

  • Loading branch information...
michield committed Sep 11, 2018
2 parents 9909a77 + 2f15e76 commit e5e76a68f958f6e63ca187535ed20c518f5038d8
@@ -30,8 +30,8 @@
}
if (isset($_POST['save']) && $_POST['save']) {
Sql_Query(sprintf('update %s set regex = "%s",action="%s", comment="%s",status = "%s" where id= %d',
$GLOBALS['tables']['bounceregex'], trim($_POST['regex']), sql_escape($_POST['action']),
Sql_Query(sprintf('update %s set regex = "%s", regexhash = "%s", action="%s", comment="%s",status = "%s" where id= %d',
$GLOBALS['tables']['bounceregex'], trim($_POST['regex']), md5(trim($_POST['regex'])), sql_escape($_POST['action']),
sql_escape($_POST['comment']), sql_escape($_POST['status']), $_GET['id']), 1);
$num = Sql_Affected_Rows();
if ($num < 0) {
@@ -46,8 +46,8 @@
}
if (isset($_POST['newrule']) && $_POST['newrule']) {
Sql_Query(sprintf('insert into %s (regex,action,comment,admin,status) values("%s","%s","%s",%d,"active")',
$GLOBALS['tables']['bounceregex'], sql_escape($_POST['newrule']), sql_escape($_POST['action']),
Sql_Query(sprintf('insert into %s (regex, regexhash, action,comment,admin,status) values("%s","%s","%s","%s",%d,"active")',
$GLOBALS['tables']['bounceregex'], sql_escape($_POST['newrule']), md5(sql_escape($_POST['newrule'])), sql_escape($_POST['action']),
sql_escape($_POST['comment']), $_SESSION['logindetails']['id']), 1);
$num = Sql_Affected_Rows();
if ($num < 0) {
@@ -617,7 +617,9 @@ function pageTitle($page)
// pages => pages in this category
'dashboard' => array(
'toplink'=> 'home',
'pages' => ''),
'pages' => array(),
'menulinks' => array(),
),
'subscribers' => array(
'toplink' => 'list',
'pages' => array(
@@ -83,12 +83,12 @@ function flushbuffer()
break;
}
$exists = Sql_Fetch_Row_Query(sprintf('select id from %s where url = "%s"', $GLOBALS['tables']['linktrack_forward'],
$row['url']));
$exists = Sql_Fetch_Row_Query(sprintf('select id from %s where urlhash = "%s"', $GLOBALS['tables']['linktrack_forward'],
md5($row['url'])));
if (!$exists[0]) {
$personalise = preg_match('/uid=/', $row['forward']);
Sql_Query(sprintf('insert into %s (url,personalise) values("%s",%d)', $GLOBALS['tables']['linktrack_forward'],
$row['url'], $personalise));
Sql_Query(sprintf('insert into %s (url, urlhash, personalise) values("%s","%s", %d)', $GLOBALS['tables']['linktrack_forward'],
$row['url'], md5($row['url']), $personalise));
$fwdid = Sql_Insert_id();
} else {
$fwdid = $exists[0];
@@ -204,7 +204,7 @@ function output($message)
SaveConfig('organisation_name', strip_tags($_REQUEST['adminemail']), 1);
}
// add a draft campaign for invite plugin
addInviteCampaign();
addInviteCampaign(1);
// add a testlist
$info = s('List for testing');
$result = Sql_query("insert into {$tables['list']} (name,description,entered,active,owner) values(\"test\",\"$info\",now(),0,1)");
@@ -1479,12 +1479,16 @@ function addSubscriberStatistics($item, $amount, $list = 0)
}
}
/**
* Insert a draft campaign for use with the Invite plugin
* @param null|int $forcedOwnerId
* @return bool|mysqli_result
* @throws Exception
* @todo Make the campaign content translatable
* @todo Add Campaign Meta Title to clarify purpose of this draft
*/
function addInviteCampaign() {
function addInviteCampaign($forcedOwnerId = null) {
$message =
'<p>Hi [FIRST NAME%%there], remember us? You first signed up for our email newsletter on&nbsp;[ENTERED] &ndash; please click here to confirm you&#39;re happy to continue receiving our messages:</p>
@@ -1502,7 +1506,11 @@ function addInviteCampaign() {
$inviteMessage = addslashes($message);
$inviteMessageSubject = "Do you want to continue receiving our messages?";
$uuid = uuid::generate(4);
$ownerid = $_SESSION['logindetails']['id'];
if ( $forcedOwnerId !== null) {
$ownerid = $forcedOwnerId;
} else {
$ownerid = $_SESSION['logindetails']['id'];
}
$footer = sql_escape(getConfig('messagefooter'));
$result = Sql_query("insert into {$GLOBALS['tables']['message']} (uuid,subject,message,entered, status, owner, footer, sendformat) values(\"$uuid\",\"$inviteMessageSubject\",\"$inviteMessage\",now(),\"draft\",\"$ownerid\",\"$footer\",\"invite\" )");
@@ -630,7 +630,7 @@
}
if ($msg['status'] == 'sent') {
$actionbuttons .= '<span class="edit">'.PageLinkButton('messages', s('Copy to Draft'),
$actionbuttons .= '<span class="copy">'.PageLinkButton('messages', s('Copy to Draft'),
'tab=draft&duplicate='.$msg['id'], '', s('Copy to Draft')).'</span>';
}
@@ -349,6 +349,22 @@ function Sql_Table_Column_Exists($table, $column)
}
}
}
/**
* Check if a specific INDEX exists in a specific table
* @param string $table The table name
* @param string $index The key name
* @return bool
*/
function table_index_exists($table, $index) {
$e = false;
if ($result = Sql_Query("SHOW INDEX FROM $table WHERE Key_name = '$index'")) {
if($result->num_rows >= 1) {
$e = true;
}
}
mysqli_free_result($result);
return $e;
}
function Sql_Check_For_Table($table)
{
@@ -1263,13 +1263,13 @@ function clickTrackLinkId($messageid, $userid, $url, $link)
* alter table phplist_linktrack_forward add index (url);
* */
$exists = Sql_Fetch_Row_Query(sprintf('select id,uuid from %s where url = "%s"',
$GLOBALS['tables']['linktrack_forward'], sql_escape(substr($url, 0, 255))));
$exists = Sql_Fetch_Row_Query(sprintf('select id,uuid from %s where urlhash = "%s"',
$GLOBALS['tables']['linktrack_forward'], md5(sql_escape($url))));
if (empty($exists[0])) {
$personalise = preg_match('/uid=/', $link);
$uuid = (string)Uuid::generate(4);
Sql_Query(sprintf('insert into %s set url = "%s", personalise = %d, uuid = "%s"',
$GLOBALS['tables']['linktrack_forward'], sql_escape($url), $personalise, $uuid));
Sql_Query(sprintf('insert into %s set url = "%s", urlhash = "%s", personalise = %d, uuid = "%s"',
$GLOBALS['tables']['linktrack_forward'], sql_escape($url), md5(sql_escape($url)), $personalise, $uuid));
$fwdid = Sql_Insert_id();
$fwduuid = $uuid;
} elseif (empty($exists[1])) {
@@ -52,12 +52,12 @@
if ($reset) {
$valuesToUpdate = array(
'header' => 'pageheader',
'footer' => 'pagefooter',
'header' => $defaultheader,
'footer' => $defaultfooter,
);
foreach ($valuesToUpdate as $key => $value){
$query = sprintf('update %s set data = "%s" where name = "%s" and id = %d', $tables['subscribepage_data'], sql_escape(getConfig($value)), $key, $reset);
$query = sprintf('update %s set data = "%s" where name = "%s" and id = %d', $tables['subscribepage_data'], sql_escape($value), $key, $reset);
Sql_Query($query);
}
}
@@ -101,7 +101,7 @@
PageURL2('spage', '', 'delete='.$p['id']), s('del')).
sprintf('<span class="view"><a class="button" target="_blank" href="%s&amp;id=%d" title="'.s('view').'">%s</a></span>',
getConfig('subscribeurl'), $p['id'], s('view')).
sprintf('<span class="resettemplate"><a class="button" href = "javascript:confirmOpenUrl(\''.htmlentities(s('Are you sure you want to reset this subscription page template?')).'\', \'%s\')" title="'.s('reset').'">%s</a></span>',
sprintf('<span class="resettemplate"><a class="button" href = "javascript:confirmOpenUrl(\''.htmlentities(s('Are you sure you want to reset this subscription page template?')).'\', \'%s\')" title="'.s('reset style to default').'">%s</a></span>',
PageURL2('spage', '', 'reset='.$p['id']), s('reset styling to default'))
);
}
@@ -249,7 +249,7 @@
'id' => array('integer not null primary key auto_increment', 'ID'),
'date' => array('datetime', 'Date received'),
'header' => array('text', 'Header of bounce'),
'data' => array('blob', 'The bounce'),
'data' => array('mediumblob', 'The bounce'),
'status' => array('varchar(255)', 'Status of this bounce'),
'comment' => array('text', 'System Comment'),
'index_1' => array('dateindex (date)', ''),
@@ -359,7 +359,7 @@
),
'urlcache' => array(
'id' => array('integer not null primary key auto_increment', 'ID'),
'url' => array('text not null', ''),
'url' => array('varchar(2083) not null', ''),
'lastmodified' => array('integer', ''),
'added' => array('datetime', ''),
'content' => array('longblob', ''),
@@ -376,21 +376,22 @@
//# keep it in for now, but could be dropped at some point
//# once all dependencies have been removed
// tables that have unique indexes on hash values : linktrack_forward, bounceregex
'linktrack' => array(
'linkid' => array('integer not null primary key auto_increment', 'Link ID'),
'messageid' => array('integer not null', 'Message ID'),
'userid' => array('integer not null', 'subscriber ID'),
'url' => array('text', 'URL to log'),
'forward' => array('text', 'URL to forward to'),
'url' => array('varchar(255)', 'URL to log'),
'forward' => array('varchar(255)', 'URL to forward to'),
'firstclick' => array('datetime', 'When first clicked'),
'latestclick' => array('timestamp', 'When last clicked'),
'clicked' => array('integer default 0', 'Number of clicks'),
'index_1' => array('midindex (messageid)', ''),
'index_2' => array('uidindex (userid)', ''),
'index_3' => array('urlindex (url(255))', ''),
'index_3' => array('urlindex (url)', ''),
'index_4' => array('miduidindex (messageid,userid)', ''),
// "index_5" => array("miduidurlindex (messageid,userid,url)",""),
'unique_1' => array('miduidurlindex (messageid,userid,url(255))', ''),
'unique_1' => array('miduidurlindex (messageid,userid,url)', ''),
),
'linktrack_ml' => array( // ml -> message link
'messageid' => array('integer not null', 'Message ID'),
@@ -425,14 +426,15 @@
),
'linktrack_forward' => array(
'id' => array('integer not null primary key auto_increment', 'forward ID'),
'url' => array('text', 'URL to log'),
'url' => array('varchar(2083)', 'URL to log'),
'urlhash' => array('char(32)', 'hash value of URL'),
'uuid' => array('varchar(36) default ""', 'UUID'),
// "forward" => array("text","URL to forward to"),
'personalise' => array('tinyint default 0', 'Forward adding the UID?'),
'index_1' => array('urlindex (url(255))', ''),
// "index_2" => array("urlforwardindex (url,forward(255))",""),
// 'unique_1' => array('fwdunique (forward (500))','Forward should be unique'),
'unique_1' => array('urlunique (url(255))', 'URL should be unique'),
'unique_1' => array('urlunique (urlhash)', 'URL should be unique'),
'index_2' => array('uuididx (uuid)', 'sys:index'),
),
'linktrack_userclick' => array(
@@ -468,14 +470,15 @@
// ),
'bounceregex' => array(
'id' => array('integer not null primary key auto_increment', 'ID'),
'regex' => array('varchar(255)', 'Regex'),
'regex' => array('varchar(2083)', 'Regex'),
'regexhash' => array('char(32)', 'hash value of regex'),
'action' => array('varchar(255)', 'Action on rule'),
'listorder' => array('integer default 0', ''),
'admin' => array('integer', ''),
'comment' => array('text', ''),
'status' => array('varchar(255)', ''),
'count' => array('integer default 0', 'Count of matching bounces on this rule'),
'unique_1' => array('regex (regex)', ''),
'unique_1' => array('regex (regexhash)', ''),
),
'bounceregex_bounce' => array(
'regex' => array('integer not null', 'Related regex'),
@@ -519,4 +522,4 @@
);
$DBstruct = $DBstructuser + $DBstructphplist; # order of tables is essential for smooth upgrade
$DBstruct = $DBstructuser + $DBstructphplist; # order of tables is essential for smooth upgrade
@@ -112,34 +112,53 @@ function output($message)
if (version_compare($dbversion, '3.3.4','<')) {
Sql_Query("alter table {$GLOBALS['tables']['bounce']} modify data mediumblob ");
$indexesToRecreate = array(
'urlcache' => array(
'urlindex' => array('value' => 'url(255)', 'unique' => false),
),
'linktrack' => array(
'urlindex' => array('value' => 'url(255)', 'unique' => false),
'miduidurlindex' => array('value' => 'messageid,userid,url(255)', 'unique' => true),
),
'linktrack_forward' => array(
'urlindex' => array('value' => 'url(255)', 'unique' => false),
'urlunique' => array('value' => 'url(255)', 'unique' => true),
)
'urlunique' => array('value' => 'urlhash', 'unique' => true),
),
'bounceregex' => array(
'regex' => array('value' => 'regexhash', 'unique'=> true),
),
);
$tablesToAlter = array(
'urlcache' => array('url'),
'linktrack' => array('url', 'forward'),
'linktrack_forward' => array('url'),
'bounceregex' => array('regex'),
);
//add columns for hash values
Sql_Query("alter table {$GLOBALS['tables']['linktrack_forward']} add urlhash char(32) ");
Sql_Query("alter table {$GLOBALS['tables']['bounceregex']} add regexhash char(32) ");
// add hash values
Sql_Query("update {$GLOBALS['tables']['linktrack_forward']} set urlhash = md5(url) where urlhash is NULL ");
Sql_Query("update {$GLOBALS['tables']['bounceregex']} set regexhash = md5(regex) where regexhash is NULL ");
foreach($indexesToRecreate as $table => $indexes) {
foreach($indexes as $indexName => $settings) {
Sql_Query("drop index $indexName on {$GLOBALS['tables'][$table]} ");
$exists = table_index_exists($GLOBALS['tables'][$table],$indexName);
if ($exists) {
Sql_Query("drop index $indexName on {$GLOBALS['tables'][$table]} ");
}
}
$alteringOperations = $tablesToAlter[$table];
foreach($alteringOperations as $operation) {
Sql_Query("alter table {$GLOBALS['tables'][$table]} modify $operation text ");
Sql_Query("alter table {$GLOBALS['tables'][$table]} modify $operation varchar(2083) ");
}
foreach($indexes as $indexName => $settings) {
@@ -149,6 +168,7 @@ function output($message)
} else {
$createStmt = 'create index';
}
Sql_Query("$createStmt $indexName on {$GLOBALS['tables'][$table]}({$settings['value']})");
}
@@ -350,9 +370,13 @@ function output($message)
}
if (version_compare($dbversion, '3.3.3','<')) {
// add a draft campaign for invite plugin
// add a draft campaign for invite plugin
addInviteCampaign();
}
if (version_compare($dbversion, '3.3.4','<')) {
Sql_Query("alter table {$GLOBALS['tables']['bounce']} modify data mediumblob ");
}
//# longblobs are better at mixing character encoding. We don't know the encoding of anything we may want to store in cache

0 comments on commit e5e76a6

Please sign in to comment.