Skip to content

Commit 7a77832

Browse files
[5.x] Fix term revisions error (#14347)
Co-authored-by: Jason Varga <jason@pixelfear.com>
1 parent 291a660 commit 7a77832

File tree

8 files changed

+11
-139
lines changed

8 files changed

+11
-139
lines changed

resources/views/terms/edit.blade.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
:initial-origin-values="{{ json_encode($originValues) }}"
2727
:initial-origin-meta="{{ json_encode($originMeta) }}"
2828
initial-site="{{ $locale }}"
29-
:initial-is-working-copy="{{ $str::bool($hasWorkingCopy) }}"
3029
:initial-is-root="{{ $str::bool($isRoot) }}"
31-
:revisions-enabled="{{ $str::bool($revisionsEnabled) }}"
3230
:initial-read-only="{{ $str::bool($readOnly) }}"
3331
:preloaded-assets="{{ json_encode($preloadedAssets) }}"
3432
:breadcrumbs="{{ $breadcrumbs->toJson() }}"

src/Http/Controllers/CP/Taxonomies/TermsController.php

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ public function edit(Request $request, $taxonomy, $term)
8787
{
8888
$this->authorize('view', $term);
8989

90-
$term = $term->fromWorkingCopy();
91-
9290
$blueprint = $term->blueprint();
9391

9492
[$values, $meta] = $this->extractFromFields($term, $blueprint);
@@ -105,9 +103,6 @@ public function edit(Request $request, $taxonomy, $term)
105103
'save' => $term->updateUrl(),
106104
'publish' => $term->publishUrl(),
107105
'unpublish' => $term->unpublishUrl(),
108-
'revisions' => $term->revisionsUrl(),
109-
'restore' => $term->restoreRevisionUrl(),
110-
'createRevision' => $term->createRevisionUrl(),
111106
'editBlueprint' => cp_route('taxonomies.blueprints.edit', [$taxonomy, $blueprint]),
112107
],
113108
'values' => array_merge($values, ['id' => $term->id()]),
@@ -138,9 +133,7 @@ public function edit(Request $request, $taxonomy, $term)
138133
'livePreviewUrl' => $localized->livePreviewUrl(),
139134
];
140135
})->all(),
141-
'hasWorkingCopy' => $term->hasWorkingCopy(),
142136
'preloadedAssets' => $this->extractAssetsFromValues($values),
143-
'revisionsEnabled' => $term->revisionsEnabled(),
144137
'breadcrumbs' => $this->breadcrumbs($taxonomy),
145138
'previewTargets' => $taxonomy->previewTargets()->all(),
146139
'itemActions' => Action::for($term, ['taxonomy' => $taxonomy->handle(), 'view' => 'form']),
@@ -166,8 +159,6 @@ public function update(Request $request, $taxonomy, $term, $site)
166159

167160
$this->authorize('update', $term);
168161

169-
$term = $term->fromWorkingCopy();
170-
171162
$term->term()->syncOriginal();
172163

173164
$fields = $term->blueprint()->fields()->addValues($request->except('id'));
@@ -197,18 +188,9 @@ public function update(Request $request, $taxonomy, $term, $site)
197188

198189
$term->slug($request->slug);
199190

200-
if ($term->revisionsEnabled() && $term->published()) {
201-
$term
202-
->makeWorkingCopy()
203-
->user(User::current())
204-
->save();
205-
} else {
206-
if (! $term->revisionsEnabled()) {
207-
$term->published($request->published);
208-
}
191+
$term->published($request->published);
209192

210-
$saved = $term->updateLastModified(User::current())->save();
211-
}
193+
$saved = $term->updateLastModified(User::current())->save();
212194

213195
[$values] = $this->extractFromFields($term, $term->blueprint());
214196

@@ -315,14 +297,7 @@ public function store(Request $request, $taxonomy, $site)
315297
->data($values)
316298
->slug($slug);
317299

318-
if ($term->revisionsEnabled()) {
319-
$term->store([
320-
'message' => $request->message,
321-
'user' => User::current(),
322-
]);
323-
} else {
324-
$saved = $term->updateLastModified(User::current())->save();
325-
}
300+
$saved = $term->updateLastModified(User::current())->save();
326301

327302
return (new TermResource($term))
328303
->additional(['saved' => $saved]);

src/Providers/RouteServiceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,6 @@ protected function bindRevisions()
361361

362362
if ($route->hasParameter('entry')) {
363363
$content = $route->parameter('entry');
364-
} elseif ($route->hasParameter('term')) {
365-
$content = $route->parameter('term');
366364
} else {
367365
throw new NotFoundHttpException;
368366
}

src/Stache/Stores/TaxonomiesStore.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public function makeItemFromFile($path, $contents)
4343
return Taxonomy::make($handle)
4444
->title(Arr::get($data, 'title'))
4545
->cascade(Arr::get($data, 'inject', []))
46-
->revisionsEnabled(Arr::get($data, 'revisions', false))
4746
->searchIndex(Arr::get($data, 'search_index'))
4847
->defaultPublishState($this->getDefaultPublishState($data))
4948
->sites($sites)

src/Taxonomies/LocalizedTerm.php

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@
3131
use Statamic\Facades\Site;
3232
use Statamic\GraphQL\ResolvesValues;
3333
use Statamic\Http\Responses\DataResponse;
34-
use Statamic\Revisions\Revisable;
3534
use Statamic\Routing\Routable;
3635
use Statamic\Search\Searchable;
3736
use Statamic\Statamic;
3837
use Statamic\Support\Str;
3938

4039
class LocalizedTerm implements Arrayable, ArrayAccess, Augmentable, BulkAugmentable, ContainsQueryableValues, Localization, Protectable, ResolvesValuesContract, Responsable, SearchableContract, Term
4140
{
42-
use ContainsSupplementalData, HasAugmentedInstance, Publishable, ResolvesValues, Revisable, Routable, Searchable, TracksLastModified, TracksQueriedColumns, TracksQueriedRelations;
41+
use ContainsSupplementalData, HasAugmentedInstance, Publishable, ResolvesValues, Routable, Searchable, TracksLastModified, TracksQueriedColumns, TracksQueriedRelations;
4342

4443
protected $locale;
4544
protected $term;
@@ -235,41 +234,6 @@ public function entriesCount()
235234
});
236235
}
237236

238-
protected function revisionKey()
239-
{
240-
return vsprintf('taxonomies/%s/%s/%s', [
241-
$this->taxonomyHandle(),
242-
$this->locale(),
243-
$this->slug(),
244-
]);
245-
}
246-
247-
protected function revisionAttributes()
248-
{
249-
return [
250-
'id' => $this->id(),
251-
'slug' => $this->slug(),
252-
'published' => $this->published(),
253-
'data' => $this->data()->except(['updated_by', 'updated_at'])->all(),
254-
];
255-
}
256-
257-
public function makeFromRevision($revision)
258-
{
259-
$entry = clone $this;
260-
261-
if (! $revision) {
262-
return $entry;
263-
}
264-
265-
$attrs = $revision->attributes();
266-
267-
return $entry
268-
->published($attrs['published'])
269-
->data($attrs['data'])
270-
->slug($attrs['slug']);
271-
}
272-
273237
public function origin()
274238
{
275239
return $this->inDefaultLocale();
@@ -289,15 +253,10 @@ public function locale($locale = null)
289253
return $this->locale;
290254
}
291255

256+
/** @deprecated */
292257
public function revisionsEnabled($enabled = null)
293258
{
294-
if (func_num_args() === 0) {
295-
return $this->term->revisionsEnabled();
296-
}
297-
298-
$this->term->revisionsEnabled($enabled);
299-
300-
return $this;
259+
return func_num_args() === 0 ? false : $this;
301260
}
302261

303262
public function editUrl()
@@ -320,21 +279,6 @@ public function unpublishUrl()
320279
return $this->cpUrl('taxonomies.terms.published.destroy');
321280
}
322281

323-
public function revisionsUrl()
324-
{
325-
return $this->cpUrl('taxonomies.terms.revisions.index');
326-
}
327-
328-
public function createRevisionUrl()
329-
{
330-
return $this->cpUrl('taxonomies.terms.revisions.store');
331-
}
332-
333-
public function restoreRevisionUrl()
334-
{
335-
return $this->cpUrl('taxonomies.terms.restore-revision');
336-
}
337-
338282
public function livePreviewUrl()
339283
{
340284
return $this->cpUrl('taxonomies.terms.preview.edit');

src/Taxonomies/Taxonomy.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Statamic\Facades\Site;
2828
use Statamic\Facades\Stache;
2929
use Statamic\Facades\URL;
30-
use Statamic\Statamic;
3130
use Statamic\Support\Str;
3231
use Statamic\Support\Traits\FluentlyGetsAndSets;
3332

@@ -43,7 +42,6 @@ class Taxonomy implements Arrayable, ArrayAccess, AugmentableContract, Contract,
4342
protected $sites = [];
4443
protected $collection;
4544
protected $defaultPublishState = true;
46-
protected $revisions = false;
4745
protected $searchIndex;
4846
protected $previewTargets = [];
4947
protected $template;
@@ -322,20 +320,10 @@ public function sites($sites = null)
322320
->args(func_get_args());
323321
}
324322

323+
/** @deprecated */
325324
public function revisionsEnabled($enabled = null)
326325
{
327-
return $this
328-
->fluentlyGetOrSet('revisions')
329-
->getter(function ($enabled) {
330-
if (! config('statamic.revisions.enabled') || ! Statamic::pro()) {
331-
return false;
332-
}
333-
334-
return false; // TODO
335-
336-
return $enabled;
337-
})
338-
->args(func_get_args());
326+
return func_num_args() === 0 ? false : $this;
339327
}
340328

341329
public function url()

src/Taxonomies/Term.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,10 @@ public function reference()
278278
return "term::{$this->id()}";
279279
}
280280

281+
/** @deprecated */
281282
public function revisionsEnabled()
282283
{
283-
return $this->taxonomy()->revisionsEnabled();
284+
return false;
284285
}
285286

286287
public function dataForLocale($locale, $data = null)

tests/Routing/RouteBindingTest.php

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ private function setupContent()
206206
Facades\Revision::shouldReceive('whereKey')->with('collections/blog/en/123')->andReturn(collect(['1' => $entryRevision]));
207207

208208
Facades\Taxonomy::make('tags')->title('Product Tags')->save();
209-
$term = tap(Facades\Term::make()->taxonomy('tags')->inDefaultLocale()->slug('bravo')->data([]))->save();
210-
$termRevision = $term->inDefaultLocale()->makeRevision()->id('2');
211-
Facades\Revision::shouldReceive('whereKey')->with('taxonomies/tags/en/bravo')->andReturn(collect(['2' => $termRevision]));
209+
Facades\Term::make()->taxonomy('tags')->inDefaultLocale()->slug('bravo')->data([])->save();
212210

213211
Facades\AssetContainer::make('files')->disk('files')->title('The Files')->save();
214212
Storage::fake('files');
@@ -456,17 +454,6 @@ function (Collection $collection, Entry $entry, Revision $revision) {
456454
'cp/custom/entries/blog/123/revisions/invalid',
457455
],
458456

459-
'cp term revision' => [
460-
'cp/custom/terms/tags/bravo/revisions/2',
461-
function (Taxonomy $taxonomy, Term $term, Revision $revision) {
462-
return $taxonomy->handle() === 'tags' && $term->id() === 'tags::bravo' && $revision->id() === '2';
463-
},
464-
],
465-
466-
'cp term missing revision' => [
467-
'cp/custom/terms/tags/bravo/revisions/invalid',
468-
],
469-
470457
'cp invalid content revision' => [
471458
'cp/custom/revisions/1',
472459
],
@@ -851,24 +838,6 @@ function (string $collection, string $entry, string $revision) {
851838
},
852839
],
853840

854-
'term revision' => [
855-
'custom/terms/tags/bravo/revisions/2',
856-
function (Taxonomy $taxonomy, Term $term, Revision $revision) {
857-
return $taxonomy->handle() === 'tags' && $term->id() === 'tags::bravo' && $revision->id() === '2';
858-
},
859-
function (string $taxonomy, string $term, string $revision) {
860-
return $taxonomy === 'tags' && $term === 'bravo' && $revision === '2';
861-
},
862-
],
863-
864-
'term missing revision' => [
865-
'custom/terms/tags/bravo/revisions/invalid',
866-
null,
867-
function (string $taxonomy, string $term, string $revision) {
868-
return $taxonomy === 'tags' && $term === 'bravo' && $revision === 'invalid';
869-
},
870-
],
871-
872841
'invalid content revision' => [
873842
'custom/revisions/1',
874843
null,

0 commit comments

Comments
 (0)