You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add get-apos-doc-id and set-apos-doc-id tasks (#5136)
* add get-apos-doc-id and set-apos-doc-id tasks
* require at the top
* add tests for changing apos doc ID
* test apos-doc-id get and set tasks
* update changelog
* remove only
* filter non existing _id values + remove req usage
* add missing usage
* remove locale when using _id
* test get-apos-doc-id without locale when using _id
---------
Co-authored-by: Harouna Traoré <haroun@users.noreply.github.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@
7
7
* Adds `stripUrlAccents` option in `@apostrophecms/i18n` module to globally control whether accents are stripped from URLs. When set to `true`, all URLs (slugs) will have accents from Latin characters removed on document creation and updates. No existing documents are modified automatically; this only affects new or updated documents. A new task `node app @apostrophecms/i18n:strip-slug-accents` is provided to update existing document slugs in the database when needed.
8
8
* Add `@apostrophecms/migration:add-missing-schema-fields` task. This task does not run database migrations.
9
9
* Translation strings added for the layout- and layout-column-widgets.
10
+
* Adds `@apostrophecms/doc:get-apos-doc-id` and `@apostrophecms/doc:set-apos-doc-id` tasks.
10
11
* New `box` schema field type
11
12
* When switching locale from the doc editor, ask if the user wants to localize the current document in the target locale or want to start a blank document.
12
13
* Introduced a new `longPolling: false` option for the `@apostrophecms/notification` module. This eliminates long-pending requests when logged in, but also slows down the delivery of notifications. The behavior can be tuned further via the `pollingInterval` option, which defaults to `5000` milliseconds.
throwself.apos.error('invalid','Either oldId or slug must be provided');
1889
+
}
1890
+
if(!locale){
1891
+
throwself.apos.error('invalid','Missing locale');
1892
+
}
1893
+
1894
+
constoriginalId=(slug&&!oldId)
1895
+
? awaitself.getAposDocId({
1896
+
slug,
1897
+
locale
1898
+
})
1899
+
: oldId;
1900
+
1901
+
constmodes=['previous','draft','published'];
1902
+
constpairs=modes.map(mode=>
1903
+
[
1904
+
`${originalId}:${locale}:${mode}`,
1905
+
`${newId}:${locale}:${mode}`
1906
+
]
1907
+
);
1908
+
1909
+
// Filter non existing from _id from the list
1910
+
constexisting=(
1911
+
awaitself.apos.doc.db
1912
+
.find(
1913
+
{_id: {$in: pairs.map(([from])=>from)}},
1914
+
{projection: {_id: 1}}
1915
+
)
1916
+
.toArray()
1917
+
)
1918
+
.map(({ _id })=>_id);
1919
+
const{ renamed }=awaitself.changeDocIds(
1920
+
pairs.filter(([from])=>existing.includes(from)),
1921
+
{keep: false}
1922
+
);
1923
+
1924
+
return{
1925
+
oldId: originalId,
1926
+
newId,
1927
+
locale,
1928
+
renamed
1929
+
};
1930
+
},
1931
+
1932
+
...legacyMigrations(self),
1933
+
...migrations(self)
1934
+
};
1935
+
},
1936
+
tasks(self){
1937
+
return{
1938
+
'get-apos-doc-id': {
1939
+
usage: 'Retrieve the aposDocId from the _id or slug, and the locale. Usage: "node app.js @apostrophecms/doc:get-apos-doc-id --_id=pfh0haxfpzowht3oi213cqos:fr:draft" or "node app.js @apostrophecms/doc:get-apos-doc-id --slug=test --locale=fr"',
1940
+
task: async(argv)=>{
1941
+
const{
1942
+
_id, slug, locale
1943
+
}=argv;
1944
+
1945
+
constaposDocId=awaitself.getAposDocId({
1946
+
_id,
1947
+
slug,
1948
+
locale
1949
+
});
1950
+
1951
+
self.apos.util.info(aposDocId);
1952
+
1953
+
returnaposDocId;
1954
+
}
1955
+
},
1956
+
'set-apos-doc-id': {
1957
+
usage: 'Change the aposDocId of an existing document. You need the new aposDocId (new-id), the old aposDocId (old-id) or the slug, and the locale. Usage: "node app.js @apostrophecms/doc:set-apos-doc-id --new-id=tz4a98xxat96iws9zmbrgj3a --old-id=pfh0haxfpzowht3oi213cqos --locale=fr" or "node app.js @apostrophecms/doc:set-apos-doc-id --new-id=tz4a98xxat96iws9zmbrgj3a --slug=test --locale=fr"',
1958
+
task: async(argv)=>{
1959
+
const{
1960
+
'new-id': newId,'old-id': oldId, slug, locale
1961
+
}=argv;
1962
+
1963
+
constresult=awaitself.setAposDocId({
1964
+
newId,
1965
+
oldId,
1966
+
slug,
1967
+
locale
1968
+
});
1969
+
1970
+
self.apos.util.info(`"${result.oldId}" has been changed to "${result.newId}" for locale "${result.locale}", ${result.renamed} documents changed.`);
0 commit comments