Skip to content

Commit

Permalink
Merge branch 'master' into DroboSQLCompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwingj committed Oct 7, 2014
2 parents 437d379 + 520cab8 commit a19dc11
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 40 deletions.
4 changes: 4 additions & 0 deletions src/configs/upgrade/db/mysql/mysql-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
`extra` text,
`countPublic` int(10) unsigned NOT NULL DEFAULT '0',
`countPrivate` int(10) unsigned NOT NULL DEFAULT '0',
`dateLastPhotoAdded` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY `owner` (`owner`,`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
SQL;
Expand Down Expand Up @@ -122,6 +123,7 @@
`element` varchar(6) NOT NULL,
`album` varchar(6) NOT NULL,
`order` smallint(11) unsigned NOT NULL DEFAULT '0',
`active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`owner`,`type`,`element`,`album`),
INDEX (`owner`,`album`)
Expand Down Expand Up @@ -151,6 +153,7 @@
`type` enum('photo') NOT NULL,
`element` varchar(6) NOT NULL DEFAULT 'photo',
`tag` varchar(127) NOT NULL,
`active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`owner`,`type`,`element`,`tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Tag mapping table for photos (and videos in the future)';
Expand Down Expand Up @@ -221,6 +224,7 @@
`albums` text,
`groups` text,
`tags` text,
`active` tinyint(1) NOT NULL DEFAULT '1',
UNIQUE KEY `owner` (`owner`,`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL;
Expand Down
15 changes: 8 additions & 7 deletions src/html/assets/javascripts/releases/4.0.2/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3237,13 +3237,14 @@

'<div class="plupload_content">' +
'<div class="plupload_filelist_footer">' +
'<div class="plupload_file_name">' +
'<div class="plupload_buttons">' +
'<a href="#" class="plupload_button plupload_add">' + _('Add photos') + '</a>' +
'<a href="#" class="plupload_button plupload_start">' + _('Start upload') + '</a>' +
'</div>' +
'<span class="plupload_upload_status"></span>' +
'</div>' +
'<div class="plupload_file_name">' +
'<div class="plupload_buttons">' +
//'<a href="#" class="plupload_button plupload_add hidden-phone">' + _('Add photos') + '</a>' +
(window.innerWidth > 480 ? '<a href="" class="btn btn-theme-tertiary" id="uploader_browse"><i class="icon-paperclip"></i> Select photos</a>&nbsp;&nbsp;<button type="submit" class="btn btn-brand upload-button addSpinner">Start uploading</button>' : '') +
'<a href="#" class="plupload_button plupload_start">' + _('Start upload') + '</a>' +
'</div>' +
'<span class="plupload_upload_status"></span>' +
'</div>' +
'<div class="plupload_file_action"></div>' +
'<div class="plupload_file_status"><span class="plupload_total_status">0%</span></div>' +
'<div class="plupload_file_size"><span class="plupload_total_file_size">0 b</span></div>' +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<?php
$user = new User;
$utilityObj = new Utility;
$configObj = getConfig();
$page = $this->plugin->getData('page');
$username = $utilityObj->safe($user->getNameFromEmail($this->config->user->email), false);

// since $this->config->user doesn't exist on first set up we have to check gh-1546
if(isset($this->config->user)) {
$username = $utilityObj->safe($user->getNameFromEmail($this->config->user->email), false);
} else {
$username = User::displayNameDefault;
}
$title = '';
?>

Expand Down
89 changes: 89 additions & 0 deletions src/libraries/adapters/DatabaseMySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,91 @@ private function addTagsToElement($id, $tags, $type)
return $res !== false;
}

// see #1342 for why we do this here instead of in a trigger
private function adjustItemCounts($items, $type)
{

if($type === 'tag')
{
$table = 'tag';
$tableMap = 'elementTag';
$column = 'tag';
}
elseif($type === 'album')
{
$table = 'album';
$tableMap = 'elementAlbum';
$column = 'album';
}
else
{
return false;
}

$itemsForSql = array();
foreach($items as $item)
$itemsForSql[] = $this->_($item);
$itemsForSql = sprintf("'%s'", implode("','", $itemsForSql));
// get public and private counts for all the items
// private item counts (omit permission column in WHERE clause to get all photos (private is everything))
$privateCounts = $this->db->all($sql = "SELECT ei.`{$column}`, COUNT(*) AS _CNT
FROM `{$this->mySqlTablePrefix}photo` AS p INNER JOIN `{$this->mySqlTablePrefix}{$tableMap}` AS ei ON ei.`element`=p.`id`
WHERE ei.`owner`=:owner1 AND ei.`{$column}` IN ({$itemsForSql}) AND p.`owner`=:owner2 AND p.`active`=1
GROUP BY ei.`{$table}`",
array(':owner1' => $this->owner, ':owner2' => $this->owner)
);

// public item counts (include permission column in WHERE clause to get only public photos)
$publicCounts = $this->db->all("SELECT ei.`{$column}`, COUNT(*) AS _CNT
FROM `{$this->mySqlTablePrefix}photo` AS p INNER JOIN `{$this->mySqlTablePrefix}{$tableMap}` AS ei ON ei.`element`=p.`id`
WHERE ei.`owner`=:owner1 AND ei.`{$column}` IN ({$itemsForSql}) AND p.`owner`=:owner2 AND p.`permission`=:permission AND p.`active`=1
GROUP BY ei.`{$column}`",
array(':owner1' => $this->owner, ':owner2' => $this->owner, ':permission' => '1')
);

// there's an edge case described by gh-1454
// counts come out of sync when the only photo in a tag or album is deleted as the
// above query returns NULL in the first column

// first we get all columns found in each query
$privateKeys = array_column($privateCounts, $column);
$privateDiff = array_diff($items, $privateKeys);
$publicKeys = array_column($publicCounts, $column);
$publicDiff = array_diff($items, $publicKeys);

if(!empty($privateDiff))
{
foreach($privateDiff as $pItem)
$privateCounts[] = array($column => $pItem, '_CNT' => 0);
}

if(!empty($publicDiff))
{
foreach($publicDiff as $pItem)
$publicCounts[] = array($column => $pItem, '_CNT' => 0);
}

$itemCountSql = "UPDATE `{$this->mySqlTablePrefix}{$table}` ";
if(count($privateCounts) > 0)
{
$itemCountSql .= 'SET `countPrivate` = CASE `id` ';
foreach($privateCounts as $t)
$itemCountSql .= sprintf("WHEN '%s' THEN '%s' ", $this->_($t[$column]), $t['_CNT']);
$itemCountSql .= "ELSE `id` END WHERE `owner`=:owner AND `id` IN({$itemsForSql})";
$this->db->execute($itemCountSql, array(':owner' => $this->owner));
}

$itemCountSql = "UPDATE `{$this->mySqlTablePrefix}{$table}` ";
if(count($publicCounts) > 0)
{
$itemCountSql .= 'SET `countPublic` = CASE `id` ';
foreach($publicCounts as $t)
$itemCountSql .= sprintf("WHEN '%s' THEN '%s' ", $this->_($t[$column]), $t['_CNT']);
$itemCountSql .= "ELSE `id` END WHERE `owner`=:owner AND `id` IN({$itemsForSql})";
$this->db->execute($itemCountSql, array(':owner' => $this->owner));
}
}

/**
* Build parts of the photos select query
*
Expand Down Expand Up @@ -1755,6 +1840,10 @@ private function buildQuery($filters, $limit, $offset, $table)
$ids = sprintf("'%s'", implode("','", $ids));
$where = "WHERE `{$this->mySqlTablePrefix}{$table}`.`owner` IN({$ids})";
}
elseif($table === 'photo')
{
$where = $this->buildWhere($where, '`active`=1');
}
$groupBy = '';

// #1341 To fix a regression for sort we set a default and apply it anytime there's no sortBy present
Expand Down
77 changes: 45 additions & 32 deletions src/libraries/compatability.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
<?php
// array_column is >= 5.5
if(!function_exists('array_column'))
{
function array_column($array, $column)
{
return array_map(function($element){ return $element[$column]; }, $array);
}
}

// parse_ini_string is >= 5.3
if(!function_exists('parse_ini_string')){
function parse_ini_string($str, $ProcessSections=false){
$lines = explode("\n", $str);
$return = Array();
$inSect = false;
foreach($lines as $line){
$line = trim($line);
if(!$line || $line[0] == "#" || $line[0] == ";")
continue;
if($line[0] == "[" && $endIdx = strpos($line, "]")){
$inSect = substr($line, 1, $endIdx-1);
continue;
}
if(!strpos($line, '=')) // (We don't use "=== false" because value 0 is not valid as well)
continue;

$tmp = explode("=", $line, 2);
$tmp[1] = preg_replace(array('/^ ?"/', '/"$/'), '', $tmp[1]);
if($ProcessSections && $inSect)
$return[$inSect][trim($tmp[0])] = ltrim($tmp[1]);
else
$return[trim($tmp[0])] = ltrim($tmp[1]);
}
return $return;
if(!function_exists('parse_ini_string'))
{
function parse_ini_string($str, $ProcessSections=false)
{
$lines = explode("\n", $str);
$return = Array();
$inSect = false;
foreach($lines as $line)
{
$line = trim($line);
if(!$line || $line[0] == "#" || $line[0] == ";")
continue;
if($line[0] == "[" && $endIdx = strpos($line, "]"))
{
$inSect = substr($line, 1, $endIdx-1);
continue;
}
if(!strpos($line, '=')) // (We don't use "=== false" because value 0 is not valid as well)
continue;

$tmp = explode("=", $line, 2);
$tmp[1] = preg_replace(array('/^ ?"/', '/"$/'), '', $tmp[1]);
if($ProcessSections && $inSect)
$return[$inSect][trim($tmp[0])] = ltrim($tmp[1]);
else
$return[trim($tmp[0])] = ltrim($tmp[1]);
}
return $return;
}
}

// finfo_open is >= 5.3
Expand All @@ -36,23 +49,23 @@ function get_mime_type($filename)
$type = null;
if(function_exists("finfo_open"))
{
// not supported everywhere https://github.com/openphoto/frontend/issues/368
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $filename);
// not supported everywhere https://github.com/openphoto/frontend/issues/368
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $filename);
}
else if(function_exists("mime_content_type"))
{
$type = mime_content_type($filename);
$type = mime_content_type($filename);
}
else if(function_exists('exec'))
{
$type = exec('/usr/bin/file --mime-type -b ' .escapeshellarg($filename));
if(empty($type))
$type = null;
$type = exec('/usr/bin/file --mime-type -b ' .escapeshellarg($filename));
if(empty($type))
$type = null;
}

return $type;
}

// password_verify and password_hash are >= 5.5
// provided in external/password_compat/password.php
// provided in external/password_compat/password.php

0 comments on commit a19dc11

Please sign in to comment.