Initial commit
This commit is contained in:
80
#pma/libraries/plugins/import/upload/UploadApc.php
Normal file
80
#pma/libraries/plugins/import/upload/UploadApc.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PMA\libraries\plugins\import\upload;
|
||||
|
||||
use PMA\libraries\plugins\UploadInterface;
|
||||
|
||||
/**
|
||||
* Implementation for the APC extension
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class UploadApc implements UploadInterface
|
||||
{
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey()
|
||||
{
|
||||
return 'APC_UPLOAD_PROGRESS';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation for APC extension.
|
||||
*
|
||||
* @param string $id upload id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
|
||||
if (trim($id) == "") {
|
||||
return null;
|
||||
}
|
||||
if (!array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => UploadApc::getIdKey(),
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
if (!PMA_Import_apcCheck() || $ret['finished']) {
|
||||
return $ret;
|
||||
}
|
||||
$status = apc_fetch('upload_' . $id);
|
||||
|
||||
if ($status) {
|
||||
$ret['finished'] = (bool)$status['done'];
|
||||
$ret['total'] = $status['total'];
|
||||
$ret['complete'] = $status['current'];
|
||||
|
||||
if ($ret['total'] > 0) {
|
||||
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
||||
}
|
||||
|
||||
if ($ret['percent'] == 100) {
|
||||
$ret['finished'] = (bool)true;
|
||||
}
|
||||
|
||||
$_SESSION[$SESSION_KEY][$id] = $ret;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
60
#pma/libraries/plugins/import/upload/UploadNoplugin.php
Normal file
60
#pma/libraries/plugins/import/upload/UploadNoplugin.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PMA\libraries\plugins\import\upload;
|
||||
|
||||
use PMA\libraries\plugins\UploadInterface;
|
||||
|
||||
/**
|
||||
* Implementation for no plugin
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class UploadNoplugin implements UploadInterface
|
||||
{
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey()
|
||||
{
|
||||
return 'noplugin';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation when no webserver support exists,
|
||||
* so it returns just zeroes.
|
||||
*
|
||||
* @param string $id upload id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
|
||||
if (trim($id) == "") {
|
||||
return null;
|
||||
}
|
||||
if (!array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => UploadNoplugin::getIdKey(),
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
91
#pma/libraries/plugins/import/upload/UploadProgress.php
Normal file
91
#pma/libraries/plugins/import/upload/UploadProgress.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PMA\libraries\plugins\import\upload;
|
||||
|
||||
use PMA\libraries\plugins\UploadInterface;
|
||||
|
||||
/**
|
||||
* Implementation for upload progress
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class UploadProgress implements UploadInterface
|
||||
{
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey()
|
||||
{
|
||||
return 'UPLOAD_IDENTIFIER';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation for upload progress
|
||||
*
|
||||
* @param string $id upload id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
|
||||
if (trim($id) == "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => UploadProgress::getIdKey(),
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
if (!PMA_Import_progressCheck() || $ret['finished']) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$status = uploadprogress_get_info($id);
|
||||
|
||||
if ($status) {
|
||||
if ($status['bytes_uploaded'] == $status['bytes_total']) {
|
||||
$ret['finished'] = true;
|
||||
} else {
|
||||
$ret['finished'] = false;
|
||||
}
|
||||
$ret['total'] = $status['bytes_total'];
|
||||
$ret['complete'] = $status['bytes_uploaded'];
|
||||
|
||||
if ($ret['total'] > 0) {
|
||||
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
||||
}
|
||||
} else {
|
||||
$ret = array(
|
||||
'id' => $id,
|
||||
'finished' => true,
|
||||
'percent' => 100,
|
||||
'total' => $ret['total'],
|
||||
'complete' => $ret['total'],
|
||||
'plugin' => UploadProgress::getIdKey(),
|
||||
);
|
||||
}
|
||||
|
||||
$_SESSION[$SESSION_KEY][$id] = $ret;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
92
#pma/libraries/plugins/import/upload/UploadSession.php
Normal file
92
#pma/libraries/plugins/import/upload/UploadSession.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PMA\libraries\plugins\import\upload;
|
||||
|
||||
use PMA\libraries\plugins\UploadInterface;
|
||||
|
||||
/**
|
||||
* Implementation for session
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class UploadSession implements UploadInterface
|
||||
{
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey()
|
||||
{
|
||||
return ini_get('session.upload_progress.name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation for session.upload_progress in PHP 5.4+.
|
||||
*
|
||||
* @param string $id upload id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
|
||||
if (trim($id) == '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => UploadSession::getIdKey(),
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
if (!PMA_Import_sessionCheck() || $ret['finished']) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$status = false;
|
||||
$sessionkey = ini_get('session.upload_progress.prefix') . $id;
|
||||
|
||||
if (isset($_SESSION[$sessionkey])) {
|
||||
$status = $_SESSION[$sessionkey];
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$ret['finished'] = $status['done'];
|
||||
$ret['total'] = $status['content_length'];
|
||||
$ret['complete'] = $status['bytes_processed'];
|
||||
|
||||
if ($ret['total'] > 0) {
|
||||
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
||||
}
|
||||
} else {
|
||||
$ret = array(
|
||||
'id' => $id,
|
||||
'finished' => true,
|
||||
'percent' => 100,
|
||||
'total' => $ret['total'],
|
||||
'complete' => $ret['total'],
|
||||
'plugin' => UploadSession::getIdKey(),
|
||||
);
|
||||
}
|
||||
|
||||
$_SESSION[$SESSION_KEY][$id] = $ret;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user