Skip to content

Commit

Permalink
Merge pull request #69 from GregMage/update
Browse files Browse the repository at this point in the history
fix onupdate.php
  • Loading branch information
ggoffy authored Jan 31, 2019
2 parents 6436ae7 + 43b4467 commit 468f1f6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 42 deletions.
11 changes: 11 additions & 0 deletions docs/Update.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Important information for updating a version below 2.0 !!!

Step:

1. Connect to your site and go to module administration.
2. Delete the folder "modules/TDMDownloads"
3. Copy the "tdmdownloads" folder (version greater than 2) to folder "modules/"
4. Update the "tdmdownloads" module
5. Go into the preferences of the module "tdmdownloads", choose "Max uploaded files size" and validate them.

tdmdownloads is now up to date.
37 changes: 21 additions & 16 deletions include/onupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function xoops_module_update_tdmdownloads(&$module, $prev_version = null)
*/
function update_tdmdownloads_v200(&$module)
{
// Update size
$db = \XoopsDatabaseFactory::getDatabaseConnection();
$sql = 'SELECT lid, size FROM ' . $db->prefix('tdmdownloads_downloads');
$result = $db->query($sql);
$helper = \XoopsModules\Tdmdownloads\Helper::getInstance();
$helper->loadLanguage('admin');
//print_r($result);
while (false !== ($myrow = $db->fetchArray($result))) {
$size_value_arr = explode(' ', $myrow['size']);
switch ($size_value_arr[1]) {
Expand Down Expand Up @@ -83,6 +83,11 @@ function update_tdmdownloads_v200(&$module)
break;
}
}
// Update folder
rename(XOOPS_ROOT_PATH . '/uploads/TDMDownloads', XOOPS_ROOT_PATH . '/uploads/tdmdownloads');
// Change TDMDownloads with tdmdownloads
$sql = 'UPDATE `' . $db->prefix('tdmdownloads_downloads') . '` SET `url` = REPLACE(`url`, \'TDMDownloads\', \'tdmdownloads\') WHERE `url` LIKE \'%TDMDownloads%\'';
$result = $db->query($sql);
return true;
}

Expand Down Expand Up @@ -110,21 +115,21 @@ function update_tdmdownloads_v167(&$module)
// unlink( XOOPS_ROOT_PATH.'/modules/tdmdownloads/admin/admin_header.php' );

// clean template directory
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_brokenfile.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_download.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_index.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_modfile.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_ratefile.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_singlefile.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_submit.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_viewcat.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_liste.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_rss.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_new.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_random.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_rating.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_search.html');
unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_top.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_brokenfile.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_download.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_index.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_modfile.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_ratefile.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_singlefile.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_submit.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_viewcat.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_liste.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/tdmdownloads_rss.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_new.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_random.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_rating.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_search.html');
@unlink(XOOPS_ROOT_PATH . '/modules/tdmdownloads/templates/blocks/tdmdownloads_block_top.html');

return true;
}
Expand Down
36 changes: 36 additions & 0 deletions include/xoops_version.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* tdmdownloads
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Gregory Mage (Aka Mage)
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Gregory Mage (Aka Mage)
*/

/**
* @param $val
* @return float|int
*/
function tdmdownloadsReturnBytes($val)
{
switch (mb_substr($val, -1)) {
case 'K':
case 'k':
return (int)$val * 1024;
case 'M':
case 'm':
return (int)$val * 1048576;
case 'G':
case 'g':
return (int)$val * 1073741824;
default:
return $val;
}
}
29 changes: 3 additions & 26 deletions xoops_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,6 @@
'default' => 0,
];

//xoops_load('xoopseditorhandler');
//$editorHandler = \XoopsEditorHandler::getInstance();

$modversion['config'][] = [
'name' => 'editor',
'title' => '_MI_TDMDOWNLOADS_FORM_OPTIONS',
Expand Down Expand Up @@ -536,8 +533,9 @@
'default' => 'downloads_',
];

$iniPostMaxSize = returnBytes(ini_get('post_max_size'));
$iniUploadMaxFileSize = returnBytes(ini_get('upload_max_filesize'));
include_once 'include/xoops_version.inc.php';
$iniPostMaxSize = tdmdownloadsReturnBytes(ini_get('post_max_size'));
$iniUploadMaxFileSize = tdmdownloadsReturnBytes(ini_get('upload_max_filesize'));
$maxSize = min($iniPostMaxSize, $iniUploadMaxFileSize);
if ($maxSize > 10000 * 1048576) {
$increment = 500;
Expand Down Expand Up @@ -894,24 +892,3 @@
'mail_template' => 'file_approve_notify',
'mail_subject' => _MI_TDMDOWNLOADS_FILE_APPROVE_NOTIFYSBJ,
];

/**
* @param $val
* @return float|int
*/
function returnBytes($val)
{
switch (mb_substr($val, -1)) {
case 'K':
case 'k':
return (int)$val * 1024;
case 'M':
case 'm':
return (int)$val * 1048576;
case 'G':
case 'g':
return (int)$val * 1073741824;
default:
return $val;
}
}

0 comments on commit 468f1f6

Please sign in to comment.