|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Mocks; |
| 4 | + |
| 5 | +use Illuminate\Cache\ArrayStore; |
| 6 | +use Illuminate\Cache\Repository; |
| 7 | +use Illuminate\Container\Container; |
| 8 | +use Illuminate\Database\Capsule\Manager as Capsule; |
| 9 | +use Illuminate\Database\Eloquent\Model; |
| 10 | +use Illuminate\Database\Schema\Blueprint; |
| 11 | +use Illuminate\Events\Dispatcher; |
| 12 | +use Illuminate\Support\Facades\Facade; |
| 13 | + |
| 14 | +/** |
| 15 | + * Stand-in for the core: only what Legacy\Cache touches while rebuilding the site cache. |
| 16 | + */ |
| 17 | +class CacheRefreshHarness |
| 18 | +{ |
| 19 | + public array $config = ['server_offset_time' => 0]; |
| 20 | + public array $events = []; |
| 21 | + public string $dir; |
| 22 | + |
| 23 | + public function getConfig($name = '', $default = null) |
| 24 | + { |
| 25 | + return $this->config[$name] ?? $default; |
| 26 | + } |
| 27 | + |
| 28 | + public function parseProperties($props, $name = null, $type = null): array |
| 29 | + { |
| 30 | + return []; |
| 31 | + } |
| 32 | + |
| 33 | + public function invokeEvent($name, $params = []) |
| 34 | + { |
| 35 | + $this->events[] = $name; |
| 36 | + return false; |
| 37 | + } |
| 38 | + |
| 39 | + public function getSiteCacheFilePath(): string |
| 40 | + { |
| 41 | + return $this->dir . '/siteCache.idx.php'; |
| 42 | + } |
| 43 | + |
| 44 | + public function getSitePublishingFilePath(): string |
| 45 | + { |
| 46 | + return $this->dir . '/sitePublishing.idx.php'; |
| 47 | + } |
| 48 | + |
| 49 | + /** Boots Eloquent (with model events) and the Cache facade against the given sqlite database. */ |
| 50 | + public static function boot(string $database = ':memory:'): Capsule |
| 51 | + { |
| 52 | + foreach (['IN_MANAGER_MODE', 'IN_INSTALL_MODE'] as $c) { |
| 53 | + defined($c) || define($c, false); |
| 54 | + } |
| 55 | + defined('EVO_API_MODE') || define('EVO_API_MODE', true); |
| 56 | + defined('EVO_CLASS') || define('EVO_CLASS', self::class); |
| 57 | + require_once dirname(__DIR__, 2) . '/functions/preload.php'; |
| 58 | + |
| 59 | + $database === ':memory:' || is_file($database) || touch($database); |
| 60 | + $capsule = new Capsule(); |
| 61 | + $capsule->addConnection(['driver' => 'sqlite', 'database' => $database, 'prefix' => '']); |
| 62 | + $capsule->setEventDispatcher(new Dispatcher(new Container())); |
| 63 | + $capsule->setAsGlobal(); |
| 64 | + $capsule->bootEloquent(); |
| 65 | + Model::setConnectionResolver($capsule->getDatabaseManager()); |
| 66 | + Model::clearBootedModels(); |
| 67 | + |
| 68 | + $container = new Container(); |
| 69 | + $container->instance('cache', new Repository(new ArrayStore())); |
| 70 | + Facade::setFacadeApplication($container); |
| 71 | + |
| 72 | + return $capsule; |
| 73 | + } |
| 74 | + |
| 75 | + public static function schema(Capsule $capsule): void |
| 76 | + { |
| 77 | + $schema = $capsule->getConnection()->getSchemaBuilder(); |
| 78 | + $schema->create('site_content', function (Blueprint $t) { |
| 79 | + $t->increments('id'); |
| 80 | + $t->string('type', 20)->default('document'); |
| 81 | + $t->string('contentType', 50)->default('text/html'); |
| 82 | + $t->string('pagetitle')->default(''); |
| 83 | + $t->string('alias', 245)->nullable()->default(''); |
| 84 | + $t->unsignedInteger('published')->default(0); |
| 85 | + $t->unsignedInteger('pub_date')->default(0); |
| 86 | + $t->unsignedInteger('unpub_date')->default(0); |
| 87 | + $t->unsignedInteger('parent')->default(0); |
| 88 | + $t->unsignedInteger('isfolder')->default(0); |
| 89 | + $t->unsignedInteger('menuindex')->default(0); |
| 90 | + $t->unsignedInteger('createdon')->default(0); |
| 91 | + $t->unsignedInteger('editedon')->default(0); |
| 92 | + $t->unsignedInteger('deleted')->default(0); |
| 93 | + $t->unsignedInteger('deletedon')->default(0); |
| 94 | + $t->unsignedInteger('alias_visible')->default(1); |
| 95 | + }); |
| 96 | + $schema->create('site_content_closure', function (Blueprint $t) { |
| 97 | + $t->increments('closure_id'); |
| 98 | + $t->unsignedInteger('ancestor'); |
| 99 | + $t->unsignedInteger('descendant'); |
| 100 | + $t->unsignedInteger('depth'); |
| 101 | + }); |
| 102 | + $schema->create('system_settings', function (Blueprint $t) { |
| 103 | + $t->string('setting_name', 50)->primary(); |
| 104 | + $t->text('setting_value')->nullable(); |
| 105 | + }); |
| 106 | + $schema->create('site_htmlsnippets', function (Blueprint $t) { |
| 107 | + $t->increments('id'); |
| 108 | + $t->string('name')->default(''); |
| 109 | + $t->text('snippet')->nullable(); |
| 110 | + $t->boolean('disabled')->default(0); |
| 111 | + }); |
| 112 | + foreach (['site_snippets' => 'snippet', 'site_plugins' => 'plugincode'] as $table => $code) { |
| 113 | + $schema->create($table, function (Blueprint $t) use ($code) { |
| 114 | + $t->increments('id'); |
| 115 | + $t->string('name')->default(''); |
| 116 | + $t->text($code)->nullable(); |
| 117 | + $t->text('properties')->nullable(); |
| 118 | + $t->string('moduleguid', 32)->default(''); |
| 119 | + $t->boolean('disabled')->default(0); |
| 120 | + }); |
| 121 | + } |
| 122 | + $schema->create('site_modules', function (Blueprint $t) { |
| 123 | + $t->increments('id'); |
| 124 | + $t->string('guid', 32)->default(''); |
| 125 | + $t->text('properties')->nullable(); |
| 126 | + }); |
| 127 | + $schema->create('system_eventnames', function (Blueprint $t) { |
| 128 | + $t->increments('id'); |
| 129 | + $t->string('name', 50)->default(''); |
| 130 | + }); |
| 131 | + $schema->create('site_plugin_events', function (Blueprint $t) { |
| 132 | + $t->unsignedInteger('pluginid'); |
| 133 | + $t->unsignedInteger('evtid'); |
| 134 | + $t->integer('priority')->default(0); |
| 135 | + }); |
| 136 | + $schema->create('user_settings', function (Blueprint $t) { |
| 137 | + $t->unsignedInteger('user'); |
| 138 | + $t->string('setting_name', 50); |
| 139 | + $t->text('setting_value')->nullable(); |
| 140 | + }); |
| 141 | + $capsule->table('system_settings')->insert([ |
| 142 | + ['setting_name' => 'friendly_urls', 'setting_value' => '1'], |
| 143 | + ['setting_name' => 'use_alias_path', 'setting_value' => '1'], |
| 144 | + ]); |
| 145 | + } |
| 146 | + |
| 147 | + /** Includes a generated site cache the way Core::recoverySiteCache() does. */ |
| 148 | + public static function listing(string $file): array |
| 149 | + { |
| 150 | + $reader = new class { |
| 151 | + public $config = [], $aliasListing = [], $documentListing = [], $documentMap = [], $contentTypes = [], $chunkCache = [], $snippetCache = [], $pluginCache = [], $pluginEvent = []; |
| 152 | + public function load(string $file): void { include $file; } |
| 153 | + }; |
| 154 | + $reader->load($file); |
| 155 | + return ['aliasListing' => $reader->aliasListing, 'documentListing' => $reader->documentListing, 'config' => $reader->config]; |
| 156 | + } |
| 157 | +} |
0 commit comments