upgrade.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. set_time_limit(0); //scanning can take ages
  3. session_write_close();
  4. $user = OC_User::getUser();
  5. $eventSource = new OC_EventSource();
  6. $listener = new UpgradeListener($eventSource);
  7. $legacy = new \OC\Files\Cache\Legacy($user);
  8. if ($legacy->hasItems()) {
  9. OC_Hook::connect('\OC\Files\Cache\Upgrade', 'migrate_path', $listener, 'upgradePath');
  10. OC_DB::beginTransaction();
  11. $upgrade = new \OC\Files\Cache\Upgrade($legacy);
  12. $count = $legacy->getCount();
  13. $eventSource->send('total', $count);
  14. $upgrade->upgradePath('/' . $user . '/files');
  15. OC_DB::commit();
  16. }
  17. \OC\Files\Cache\Upgrade::upgradeDone($user);
  18. $eventSource->send('done', true);
  19. $eventSource->close();
  20. class UpgradeListener {
  21. /**
  22. * @var OC_EventSource $eventSource
  23. */
  24. private $eventSource;
  25. private $count = 0;
  26. private $lastSend = 0;
  27. public function __construct($eventSource) {
  28. $this->eventSource = $eventSource;
  29. }
  30. public function upgradePath($path) {
  31. $this->count++;
  32. if ($this->count > ($this->lastSend + 5)) {
  33. $this->lastSend = $this->count;
  34. $this->eventSource->send('count', $this->count);
  35. }
  36. }
  37. }