Skip to content

Commit

Permalink
Renames 'site rename' to 'tenant site rename'. Closes #6142
Browse files Browse the repository at this point in the history
  • Loading branch information
MathijsVerbeeck authored and milanholemans committed Sep 21, 2024
1 parent 863e29d commit 979b9b7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/docs/about/release-notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,7 @@ sidebar_position: 3
**SharePoint:**

- [spo feature disable](../cmd/spo/feature/feature-disable.mdx) - disables feature for the specified site or web [#676](https://github.com/pnp/cli-microsoft365/issues/676)
- [spo site rename](../cmd/spo/site/site-rename.mdx) - renames the URL and title of a site collection [#1197](https://github.com/pnp/cli-microsoft365/issues/1197)
- [spo site rename](../cmd/spo/tenant/tenant-site-rename.mdx) - renames the URL and title of a site collection [#1197](https://github.com/pnp/cli-microsoft365/issues/1197)

**Yammer:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Global from '/docs/cmd/_global.mdx';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# spo site rename
# spo tenant site rename

Renames the URL and title of a site collection

## Usage

```sh
m365 spo site rename [options]
m365 spo tenant site rename [options]
```

## Options
Expand Down Expand Up @@ -38,7 +38,7 @@ m365 spo site rename [options]

## Remarks

Renaming site collections is by default asynchronous and depending on the current state of Microsoft 365, might take up to few minutes. If you're building a script with steps that require the operation to complete fully, you should use the `--wait` flag. When using this flag, the `spo site rename` command will keep running until it receives confirmation from Microsoft 365 that the site rename operation has completed.
Renaming site collections is by default asynchronous and depending on the current state of Microsoft 365, might take up to few minutes. If you're building a script with steps that require the operation to complete fully, you should use the `--wait` flag. When using this flag, the `spo tenant site rename` command will keep running until it receives confirmation from Microsoft 365 that the site rename operation has completed.

:::info

Expand All @@ -51,19 +51,19 @@ To use this command you must have permissions to access the tenant admin site.
Starts the rename of the site collection with name "samplesite" to "renamed" without modifying the title

```sh
m365 spo site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed
m365 spo tenant site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed
```

Starts the rename of the site collection with name "samplesite" to "renamed" modifying the title of the site to "New Title"

```sh
m365 spo site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed --newTitle "New Title"
m365 spo tenant site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed --newTitle "New Title"
```

Renames the specified site collection and waits for the operation to complete

```sh
m365 spo site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed --newTitle "New Title" --wait
m365 spo tenant site rename --url http://contoso.sharepoint.com/samplesite --newUrl http://contoso.sharepoint.com/renamed --newTitle "New Title" --wait
```

## Response
Expand Down Expand Up @@ -130,7 +130,7 @@ m365 spo site rename --url http://contoso.sharepoint.com/samplesite --newUrl htt
<TabItem value="Markdown">

```md
# spo site rename --url "https://contoso.sharepoint.com/sites/team1" --newUrl "https://contoso.sharepoint.com/sites/team2"
# spo tenant site rename --url "https://contoso.sharepoint.com/sites/team1" --newUrl "https://contoso.sharepoint.com/sites/team2"

Date: 2023-06-21

Expand Down
8 changes: 8 additions & 0 deletions docs/docs/v10-upgrade-guidance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ We updated the output from the [`spo sitescript get`](./cmd/spo/sitescript/sites

Please update your scripts to reflect the new output of the [`spo sitescript get`](./cmd/spo/sitescript/sitescript-get.mdx) command.

### Renamed `spo site rename` to `spo tenant site rename`

The `spo site rename` command was renamed to [`spo tenant site rename`](./cmd/spo/tenant/tenant-site-rename.mdx) to better reflect the command's purpose as this is an action that only an administrator can do.

#### What action do I need to take?

Please update your scripts to use the new command name.

## SharePoint Framework

### Removed overwrite option from `spfx project github workflow add` command
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/v6-upgrade-guidance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ pa solution reference add|`path`|`projectPath`
[spo site apppermission set](./cmd/spo/site/site-apppermission-set.mdx)|`permissionId`|`id`
[spo site chrome set](./cmd/spo/site/site-chrome-set.mdx)|`url`|`siteUrl`
[spo site groupify](./cmd/spo/site/site-groupify.mdx)|`siteUrl`|`url`
[spo site rename](./cmd/spo/site/site-rename.mdx)|`siteUrl`|`url`
[spo site rename](./cmd/spo/tenant/tenant-site-rename.mdx)|`siteUrl`|`url`
[spo sitedesign rights grant](./cmd/spo/sitedesign/sitedesign-rights-grant.mdx)|`id`|`siteDesignId`
[spo sitedesign rights list](./cmd/spo/sitedesign/sitedesign-rights-list.mdx)|`id`|`siteDesignId`
[spo sitedesign rights revoke](./cmd/spo/sitedesign/sitedesign-rights-revoke.mdx)|`id`|`siteDesignId`
Expand Down
10 changes: 5 additions & 5 deletions docs/src/config/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3402,11 +3402,6 @@ const sidebars: SidebarsConfig = {
label: 'site remove',
id: 'cmd/spo/site/site-remove'
},
{
type: 'doc',
label: 'site rename',
id: 'cmd/spo/site/site-rename'
},
{
type: 'doc',
label: 'site set',
Expand Down Expand Up @@ -3743,6 +3738,11 @@ const sidebars: SidebarsConfig = {
label: 'tenant site archive',
id: 'cmd/spo/tenant/tenant-site-archive'
},
{
type: 'doc',
label: 'tenant site rename',
id: 'cmd/spo/tenant/tenant-site-rename'
},
{
type: 'doc',
label: 'tenant site unarchive',
Expand Down
2 changes: 1 addition & 1 deletion src/m365/spo/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ export default {
SITE_RECYCLEBINITEM_REMOVE: `${prefix} site recyclebinitem remove`,
SITE_RECYCLEBINITEM_RESTORE: `${prefix} site recyclebinitem restore`,
SITE_REMOVE: `${prefix} site remove`,
SITE_RENAME: `${prefix} site rename`,
SITE_SET: `${prefix} site set`,
SITE_CHROME_SET: `${prefix} site chrome set`,
SITEDESIGN_ADD: `${prefix} sitedesign add`,
Expand Down Expand Up @@ -322,6 +321,7 @@ export default {
TENANT_SETTINGS_LIST: `${prefix} tenant settings list`,
TENANT_SETTINGS_SET: `${prefix} tenant settings set`,
TENANT_SITE_ARCHIVE: `${prefix} tenant site archive`,
TENANT_SITE_RENAME: `${prefix} tenant site rename`,
TENANT_SITE_UNARCHIVE: `${prefix} tenant site unarchive`,
TERM_ADD: `${prefix} term add`,
TERM_GET: `${prefix} term get`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { session } from '../../../../utils/session.js';
import { sinonUtil } from '../../../../utils/sinonUtil.js';
import { spo } from '../../../../utils/spo.js';
import commands from '../../commands.js';
import command from './site-rename.js';
import command from './tenant-site-rename.js';
import { settingsNames } from '../../../../settingsNames.js';
import { timersUtil } from '../../../../utils/timersUtil.js';

describe(commands.SITE_RENAME, () => {
describe(commands.TENANT_SITE_RENAME, () => {
let log: string[];
let logger: Logger;
let loggerLogSpy: sinon.SinonSpy;
Expand All @@ -27,10 +28,7 @@ describe(commands.SITE_RENAME, () => {
sinon.stub(telemetry, 'trackEvent').returns();
sinon.stub(pid, 'getProcessName').returns('');
sinon.stub(session, 'getId').returns('');
sinon.stub(global, 'setTimeout').callsFake((fn) => {
fn();
return {} as any;
});
sinon.stub(timersUtil, 'setTimeout').resolves();
auth.connection.active = true;
auth.connection.spoUrl = 'https://contoso.sharepoint.com';
commandInfo = cli.getCommandInfo(command);
Expand Down Expand Up @@ -73,7 +71,7 @@ describe(commands.SITE_RENAME, () => {
});

it('has correct name', () => {
assert.strictEqual(command.name, commands.SITE_RENAME);
assert.strictEqual(command.name, commands.TENANT_SITE_RENAME);
});

it('has a description', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Logger } from '../../../../cli/Logger.js';
import GlobalOptions from '../../../../GlobalOptions.js';
import request from '../../../../request.js';
import request, { CliRequestOptions } from '../../../../request.js';
import { formatting } from '../../../../utils/formatting.js';
import { FormDigestInfo, spo } from '../../../../utils/spo.js';
import { timersUtil } from '../../../../utils/timersUtil.js';
import SpoCommand from '../../../base/SpoCommand.js';
import commands from '../../commands.js';

Expand All @@ -24,13 +25,13 @@ interface SiteRenameJob {
JobState: string;
}

class SpoSiteRenameCommand extends SpoCommand {
class SpoTenantSiteRenameCommand extends SpoCommand {
private context?: FormDigestInfo;
private operationData?: SiteRenameJob;
private static readonly checkIntervalInMs: number = 5000;

public get name(): string {
return commands.SITE_RENAME;
return commands.TENANT_SITE_RENAME;
}

public get description(): string {
Expand All @@ -48,10 +49,10 @@ class SpoSiteRenameCommand extends SpoCommand {
#initTelemetry(): void {
this.telemetry.push((args: CommandArgs) => {
Object.assign(this.telemetryProperties, {
newTitle: args.options.newTitle ? true : false,
suppressMarketplaceAppCheck: args.options.suppressMarketplaceAppCheck,
suppressWorkflow2013Check: args.options.suppressWorkflow2013Check,
wait: args.options.wait
newTitle: typeof args.options.newTitle !== 'undefined',
suppressMarketplaceAppCheck: !!args.options.suppressMarketplaceAppCheck,
suppressWorkflow2013Check: !!args.options.suppressWorkflow2013Check,
wait: !!args.options.wait
});
});
}
Expand Down Expand Up @@ -111,27 +112,25 @@ class SpoSiteRenameCommand extends SpoCommand {
optionsBitmask = optionsBitmask | 16;
}

const requestOptions = {
"SourceSiteUrl": options.url,
"TargetSiteUrl": options.newUrl,
"TargetSiteTitle": options.newTitle || null,
"Option": optionsBitmask,
"Reserve": null,
"SkipGestures": null,
"OperationId": "00000000-0000-0000-0000-000000000000"
};

const postData: any = {
const requestOptions: CliRequestOptions = {
url: `${spoAdminUrl}/_api/SiteRenameJobs?api-version=1.4.7`,
headers: {
'X-RequestDigest': this.context.FormDigestValue,
'Content-Type': 'application/json'
},
responseType: 'json',
data: requestOptions
data: {
SourceSiteUrl: options.url,
TargetSiteUrl: options.newUrl,
TargetSiteTitle: options.newTitle || null,
Option: optionsBitmask,
Reserve: null,
SkipGestures: null,
OperationId: '00000000-0000-0000-0000-000000000000'
}
};

const res = await request.post<SiteRenameJob>(postData);
const res = await request.post<SiteRenameJob>(requestOptions);

if (options.verbose) {
await logger.logToStderr(res);
Expand Down Expand Up @@ -160,10 +159,10 @@ class SpoSiteRenameCommand extends SpoCommand {
}
}

protected async waitForRenameCompletion(command: SpoSiteRenameCommand, isVerbose: boolean, spoAdminUrl: string, siteUrl: string, iteration: number): Promise<void> {
protected async waitForRenameCompletion(command: SpoTenantSiteRenameCommand, isVerbose: boolean, spoAdminUrl: string, siteUrl: string, iteration: number): Promise<void> {
iteration++;

const requestOptions: any = {
const requestOptions: CliRequestOptions = {
url: `${spoAdminUrl}/_api/SiteRenameJobs/GetJobsBySiteUrl(url='${formatting.encodeQueryParameter(siteUrl)}')?api-version=1.4.7`,
headers: {
'X-AttemptNumber': iteration.toString()
Expand All @@ -182,13 +181,9 @@ class SpoSiteRenameCommand extends SpoCommand {
return;
}

await this.sleep(SpoSiteRenameCommand.checkIntervalInMs);
await timersUtil.setTimeout(SpoTenantSiteRenameCommand.checkIntervalInMs);
await command.waitForRenameCompletion(command, isVerbose, spoAdminUrl, siteUrl, iteration);
}

protected sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
}

export default new SpoSiteRenameCommand();
export default new SpoTenantSiteRenameCommand();

0 comments on commit 979b9b7

Please sign in to comment.