UploadApc.class.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Provides upload functionalities for the import plugins
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /* Get the transformations interface */
  12. require_once 'libraries/plugins/UploadInterface.int.php';
  13. /**
  14. * Implementation for the APC extension
  15. *
  16. * @package PhpMyAdmin
  17. */
  18. class UploadApc implements UploadInterface
  19. {
  20. /**
  21. * Gets the specific upload ID Key
  22. *
  23. * @return string ID Key
  24. */
  25. public static function getIdKey()
  26. {
  27. return 'APC_UPLOAD_PROGRESS';
  28. }
  29. /**
  30. * Returns upload status.
  31. *
  32. * This is implementation for APC extension.
  33. *
  34. * @param string $id upload id
  35. *
  36. * @return array|null
  37. */
  38. public static function getUploadStatus($id)
  39. {
  40. global $SESSION_KEY;
  41. if (trim($id) == "") {
  42. return null;
  43. }
  44. if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
  45. $_SESSION[$SESSION_KEY][$id] = array(
  46. 'id' => $id,
  47. 'finished' => false,
  48. 'percent' => 0,
  49. 'total' => 0,
  50. 'complete' => 0,
  51. 'plugin' => UploadApc::getIdKey()
  52. );
  53. }
  54. $ret = $_SESSION[$SESSION_KEY][$id];
  55. if (! PMA_import_apcCheck() || $ret['finished']) {
  56. return $ret;
  57. }
  58. $status = apc_fetch('upload_' . $id);
  59. if ($status) {
  60. $ret['finished'] = (bool)$status['done'];
  61. $ret['total'] = $status['total'];
  62. $ret['complete'] = $status['current'];
  63. if ($ret['total'] > 0) {
  64. $ret['percent'] = $ret['complete'] / $ret['total'] * 100;
  65. }
  66. if ($ret['percent'] == 100) {
  67. $ret['finished'] = (bool)true;
  68. }
  69. $_SESSION[$SESSION_KEY][$id] = $ret;
  70. }
  71. return $ret;
  72. }
  73. }
  74. ?>