aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Updater.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2019-07-27 12:34:30 +0200
committerArthurHoaro <arthur@hoa.ro>2019-07-27 12:34:30 +0200
commit38672ba0d1c722e5d6d33a58255ceb55e9410e46 (patch)
treedae4c7c47532380eac3ae641db99122fc77c93dc /application/Updater.php
parent83faedadff76c5bdca036f39f13943f63b27e164 (diff)
parent1e77e0448bbd25675d8c0fe4a73206ad9048904b (diff)
downloadShaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.gz
Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.zst
Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.zip
Merge tag 'v0.10.4' into stable
Release v0.10.4
Diffstat (limited to 'application/Updater.php')
-rw-r--r--application/Updater.php96
1 files changed, 94 insertions, 2 deletions
diff --git a/application/Updater.php b/application/Updater.php
index 034b8ed8..86a21fc3 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -2,6 +2,7 @@
2use Shaarli\Config\ConfigJson; 2use Shaarli\Config\ConfigJson;
3use Shaarli\Config\ConfigPhp; 3use Shaarli\Config\ConfigPhp;
4use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5use Shaarli\Thumbnailer;
5 6
6/** 7/**
7 * Class Updater. 8 * Class Updater.
@@ -31,6 +32,11 @@ class Updater
31 protected $isLoggedIn; 32 protected $isLoggedIn;
32 33
33 /** 34 /**
35 * @var array $_SESSION
36 */
37 protected $session;
38
39 /**
34 * @var ReflectionMethod[] List of current class methods. 40 * @var ReflectionMethod[] List of current class methods.
35 */ 41 */
36 protected $methods; 42 protected $methods;
@@ -42,13 +48,17 @@ class Updater
42 * @param LinkDB $linkDB LinkDB instance. 48 * @param LinkDB $linkDB LinkDB instance.
43 * @param ConfigManager $conf Configuration Manager instance. 49 * @param ConfigManager $conf Configuration Manager instance.
44 * @param boolean $isLoggedIn True if the user is logged in. 50 * @param boolean $isLoggedIn True if the user is logged in.
51 * @param array $session $_SESSION (by reference)
52 *
53 * @throws ReflectionException
45 */ 54 */
46 public function __construct($doneUpdates, $linkDB, $conf, $isLoggedIn) 55 public function __construct($doneUpdates, $linkDB, $conf, $isLoggedIn, &$session = [])
47 { 56 {
48 $this->doneUpdates = $doneUpdates; 57 $this->doneUpdates = $doneUpdates;
49 $this->linkDB = $linkDB; 58 $this->linkDB = $linkDB;
50 $this->conf = $conf; 59 $this->conf = $conf;
51 $this->isLoggedIn = $isLoggedIn; 60 $this->isLoggedIn = $isLoggedIn;
61 $this->session = &$session;
52 62
53 // Retrieve all update methods. 63 // Retrieve all update methods.
54 $class = new ReflectionClass($this); 64 $class = new ReflectionClass($this);
@@ -173,7 +183,7 @@ class Updater
173 } 183 }
174 } 184 }
175 185
176 try{ 186 try {
177 $this->conf->write($this->isLoggedIn); 187 $this->conf->write($this->isLoggedIn);
178 return true; 188 return true;
179 } catch (IOException $e) { 189 } catch (IOException $e) {
@@ -447,6 +457,88 @@ class Updater
447 $this->linkDB->save($this->conf->get('resource.page_cache')); 457 $this->linkDB->save($this->conf->get('resource.page_cache'));
448 return true; 458 return true;
449 } 459 }
460
461 /**
462 * Change privateonly session key to visibility.
463 */
464 public function updateMethodVisibilitySession()
465 {
466 if (isset($_SESSION['privateonly'])) {
467 unset($_SESSION['privateonly']);
468 $_SESSION['visibility'] = 'private';
469 }
470 return true;
471 }
472
473 /**
474 * Add download size and timeout to the configuration file
475 *
476 * @return bool true if the update is successful, false otherwise.
477 */
478 public function updateMethodDownloadSizeAndTimeoutConf()
479 {
480 if ($this->conf->exists('general.download_max_size')
481 && $this->conf->exists('general.download_timeout')
482 ) {
483 return true;
484 }
485
486 if (! $this->conf->exists('general.download_max_size')) {
487 $this->conf->set('general.download_max_size', 1024*1024*4);
488 }
489
490 if (! $this->conf->exists('general.download_timeout')) {
491 $this->conf->set('general.download_timeout', 30);
492 }
493
494 $this->conf->write($this->isLoggedIn);
495 return true;
496 }
497
498 /**
499 * * Move thumbnails management to WebThumbnailer, coming with new settings.
500 */
501 public function updateMethodWebThumbnailer()
502 {
503 if ($this->conf->exists('thumbnails.mode')) {
504 return true;
505 }
506
507 $thumbnailsEnabled = extension_loaded('gd') && $this->conf->get('thumbnail.enable_thumbnails', true);
508 $this->conf->set('thumbnails.mode', $thumbnailsEnabled ? Thumbnailer::MODE_ALL : Thumbnailer::MODE_NONE);
509 $this->conf->set('thumbnails.width', 125);
510 $this->conf->set('thumbnails.height', 90);
511 $this->conf->remove('thumbnail');
512 $this->conf->write(true);
513
514 if ($thumbnailsEnabled) {
515 $this->session['warnings'][] = t(
516 'You have enabled or changed thumbnails mode. <a href="?do=thumbs_update">Please synchronize them</a>.'
517 );
518 }
519
520 return true;
521 }
522
523 /**
524 * Set sticky = false on all links
525 *
526 * @return bool true if the update is successful, false otherwise.
527 */
528 public function updateMethodSetSticky()
529 {
530 foreach ($this->linkDB as $key => $link) {
531 if (isset($link['sticky'])) {
532 return true;
533 }
534 $link['sticky'] = false;
535 $this->linkDB[$key] = $link;
536 }
537
538 $this->linkDB->save($this->conf->get('resource.page_cache'));
539
540 return true;
541 }
450} 542}
451 543
452/** 544/**