oop: import/upload interface and classes
This commit is contained in:
parent
c10ee4dc9f
commit
89570a5475
@ -44,7 +44,7 @@ if (empty($import_list)) {
|
||||
$('#upload_form_status').css("display", "inline"); // show progress bar
|
||||
$('#upload_form_status_info').css("display", "inline"); // - || -
|
||||
<?php
|
||||
if ($_SESSION[$SESSION_KEY]["handler"]!="noplugin") {
|
||||
if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") {
|
||||
?>
|
||||
var finished = false;
|
||||
var percent = 0.0;
|
||||
@ -161,10 +161,12 @@ if ($_SESSION[$SESSION_KEY]["handler"]!="noplugin") {
|
||||
</script>
|
||||
<form action="import.php" method="post" enctype="multipart/form-data"
|
||||
name="import"<?php
|
||||
if ($_SESSION[$SESSION_KEY]["handler"]!="noplugin") {
|
||||
if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") {
|
||||
echo ' target="import_upload_iframe"';
|
||||
} ?>>
|
||||
<input type="hidden" name="<?php echo $ID_KEY; ?>" value="<?php echo $upload_id ; ?>" />
|
||||
<input type="hidden" name="<?php
|
||||
echo $_SESSION[$SESSION_KEY]["handler"]::getIdKey();
|
||||
?>" value="<?php echo $upload_id ; ?>" />
|
||||
<?php
|
||||
if ($import_type == 'server') {
|
||||
echo PMA_generate_common_hidden_inputs('', '', 1);
|
||||
|
||||
@ -5,10 +5,10 @@
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
if (!defined('PHPMYADMIN')) {
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* constant for differenciating array in $_SESSION variable
|
||||
*/
|
||||
@ -32,7 +32,7 @@ $upload_id = uniqid("");
|
||||
*/
|
||||
$plugins = array(
|
||||
"session",
|
||||
"uploadprogress",
|
||||
"progress",
|
||||
"apc",
|
||||
"noplugin"
|
||||
);
|
||||
@ -42,8 +42,9 @@ foreach ($plugins as $plugin) {
|
||||
$check = "PMA_import_" . $plugin . "Check";
|
||||
|
||||
if ($check()) {
|
||||
$_SESSION[$SESSION_KEY]["handler"] = $plugin;
|
||||
include_once "import/upload/" . $plugin . ".php";
|
||||
$upload_class = "Upload" . ucwords($plugin);
|
||||
$_SESSION[$SESSION_KEY]["handler"] = $upload_class;
|
||||
include_once "import/upload/" . $plugin . ".class.php";
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -71,7 +72,7 @@ function PMA_import_apcCheck()
|
||||
* @return boolean true if UploadProgress extension is available,
|
||||
* false if it is not
|
||||
*/
|
||||
function PMA_import_uploadprogressCheck()
|
||||
function PMA_import_progressCheck()
|
||||
{
|
||||
if (! function_exists("uploadprogress_get_info")
|
||||
|| ! function_exists('getallheaders')
|
||||
|
||||
@ -71,6 +71,7 @@ class PluginManager implements SplSubject
|
||||
* the role of sending a notification to all of the plugins in $_storage,
|
||||
* by calling the update() method for each of them.
|
||||
*
|
||||
* @todo implement
|
||||
* @return void
|
||||
*/
|
||||
function notify ()
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Abstract class for the transformations plugins
|
||||
* Interface for the transformations plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
@ -28,7 +28,6 @@ abstract class TransformationsPlugin extends PluginObserver
|
||||
*
|
||||
* @param array $options transformation options
|
||||
*
|
||||
* @todo implement
|
||||
* @return void
|
||||
*/
|
||||
public function applyTransformationNoWrap($options = array())
|
||||
|
||||
35
libraries/plugins/UploadInterface.int.php
Normal file
35
libraries/plugins/UploadInterface.int.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Interface for the import->upload plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a common interface that will have to implemented by all of the
|
||||
* import->upload plugins.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
interface UploadInterface {
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey();
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus();
|
||||
}
|
||||
?>
|
||||
@ -28,7 +28,7 @@ require_once "libraries/plugins/import/PMA_ShapeRecord.class.php";
|
||||
* @package PhpMyAdmin-Import
|
||||
*/
|
||||
class ImportShp extends ImportPlugin
|
||||
{
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
84
libraries/plugins/import/upload/UploadApc.class.php
Normal file
84
libraries/plugins/import/upload/UploadApc.class.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the transformations interface */
|
||||
require_once "libraries/plugins/UploadInterface.int.php";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
64
libraries/plugins/import/upload/UploadNoplugin.class.php
Normal file
64
libraries/plugins/import/upload/UploadNoplugin.class.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the transformations interface */
|
||||
require_once "libraries/plugins/UploadInterface.int.php";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
94
libraries/plugins/import/upload/UploadProgress.class.php
Normal file
94
libraries/plugins/import/upload/UploadProgress.class.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the transformations interface */
|
||||
require_once "libraries/plugins/UploadInterface.int.php";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
96
libraries/plugins/import/upload/UploadSession.class.php
Normal file
96
libraries/plugins/import/upload/UploadSession.class.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the transformations interface */
|
||||
require_once "libraries/plugins/UploadInterface.int.php";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user