Backup of db before drupal security update
[yaffs-website] / web / core / modules / update / src / UpdateRootFactory.php
1 <?php
2
3 namespace Drupal\update;
4
5 use Drupal\Core\DrupalKernelInterface;
6 use Symfony\Component\HttpFoundation\RequestStack;
7
8 /**
9  * Gets the root path used by the Update Manager to install or update projects.
10  */
11 class UpdateRootFactory {
12
13   /**
14    * The Drupal kernel.
15    *
16    * @var \Drupal\Core\DrupalKernelInterface
17    */
18   protected $drupalKernel;
19
20   /**
21    * The request stack.
22    *
23    * @var \Symfony\Component\HttpFoundation\RequestStack
24    */
25   protected $requestStack;
26
27   /**
28    * Constructs an UpdateRootFactory instance.
29    *
30    * @param \Drupal\Core\DrupalKernelInterface $drupal_kernel
31    *   The Drupal kernel.
32    * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
33    *   The request stack.
34    */
35   public function __construct(DrupalKernelInterface $drupal_kernel, RequestStack $request_stack) {
36     $this->drupalKernel = $drupal_kernel;
37     $this->requestStack = $request_stack;
38   }
39
40   /**
41    * Gets the root path under which projects are installed or updated.
42    *
43    * The Update Manager will ensure that project files can only be copied to
44    * specific subdirectories of this root path.
45    *
46    * @return string
47    */
48   public function get() {
49     // Normally the Update Manager's root path is the same as the app root (the
50     // directory in which the Drupal site is installed).
51     $root_path = $this->drupalKernel->getAppRoot();
52
53     // When running in a test site, change the root path to be the testing site
54     // directory. This ensures that it will always be writable by the webserver
55     // (thereby allowing the actual extraction and installation of projects by
56     // the Update Manager to be tested) and also ensures that new project files
57     // added there won't be visible to the parent site and will be properly
58     // cleaned up once the test finishes running. This is done here (rather
59     // than having the tests enable a module which overrides the update root
60     // factory service) to ensure that the parent site is automatically kept
61     // clean without relying on test authors to take any explicit steps. See
62     // also \Drupal\update\Tests\UpdateTestBase::setUp().
63     if (DRUPAL_TEST_IN_CHILD_SITE) {
64       $kernel = $this->drupalKernel;
65       $request = $this->requestStack->getCurrentRequest();
66       $root_path .= '/' . $kernel::findSitePath($request);
67     }
68
69     return $root_path;
70   }
71
72 }