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