UploadApc.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. namespace PhpMyAdmin\Plugins\Import\Upload;
  9. use PhpMyAdmin\Display\ImportAjax;
  10. use PhpMyAdmin\Plugins\UploadInterface;
  11. /**
  12. * Implementation for the APC extension
  13. *
  14. * @package PhpMyAdmin
  15. */
  16. class UploadApc implements UploadInterface
  17. {
  18. /**
  19. * Gets the specific upload ID Key
  20. *
  21. * @return string ID Key
  22. */
  23. public static function getIdKey()
  24. {
  25. return 'APC_UPLOAD_PROGRESS';
  26. }
  27. /**
  28. * Returns upload status.
  29. *
  30. * This is implementation for APC extension.
  31. *
  32. * @param string $id upload id
  33. *
  34. * @return array|null
  35. */
  36. public static function getUploadStatus($id)
  37. {
  38. global $SESSION_KEY;
  39. if (trim($id) == "") {
  40. return null;
  41. }
  42. if (!array_key_exists($id, $_SESSION[$SESSION_KEY])) {
  43. $_SESSION[$SESSION_KEY][$id] = array(
  44. 'id' => $id,
  45. 'finished' => false,
  46. 'percent' => 0,
  47. 'total' => 0,
  48. 'complete' => 0,
  49. 'plugin' => UploadApc::getIdKey(),
  50. );
  51. }
  52. $ret = $_SESSION[$SESSION_KEY][$id];
  53. if (!ImportAjax::apcCheck() || $ret['finished']) {
  54. return $ret;
  55. }
  56. $status = apc_fetch('upload_' . $id);
  57. if ($status) {
  58. $ret['finished'] = (bool)$status['done'];
  59. $ret['total'] = $status['total'];
  60. $ret['complete'] = $status['current'];
  61. if ($ret['total'] > 0) {
  62. $ret['percent'] = $ret['complete'] / $ret['total'] * 100;
  63. }
  64. if ($ret['percent'] == 100) {
  65. $ret['finished'] = (bool)true;
  66. }
  67. $_SESSION[$SESSION_KEY][$id] = $ret;
  68. }
  69. return $ret;
  70. }
  71. }