@automattic/vip 4.1.6 → 4.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/dev-env.lando.template.yml.ejs +1 -1
- package/dist/bin/vip-app-deploy-token-generate.js +110 -78
- package/dist/bin/vip-app-deploy-token.js +24 -16
- package/dist/bin/vip-app-deploy-validate.js +45 -41
- package/dist/bin/vip-app-deploy.js +222 -215
- package/dist/bin/vip-app-list.js +59 -43
- package/dist/bin/vip-app.js +97 -66
- package/dist/bin/vip-backup-db.js +36 -29
- package/dist/bin/vip-backup.js +16 -9
- package/dist/bin/vip-cache-purge-url.js +93 -55
- package/dist/bin/vip-cache.js +23 -14
- package/dist/bin/vip-config-envvar-delete.js +74 -73
- package/dist/bin/vip-config-envvar-get-all.js +68 -68
- package/dist/bin/vip-config-envvar-get.js +46 -46
- package/dist/bin/vip-config-envvar-list.js +54 -57
- package/dist/bin/vip-config-envvar-set.js +102 -96
- package/dist/bin/vip-config-envvar.js +38 -24
- package/dist/bin/vip-config-software-get.js +88 -75
- package/dist/bin/vip-config-software-update.js +116 -120
- package/dist/bin/vip-config-software.js +31 -21
- package/dist/bin/vip-config.js +25 -17
- package/dist/bin/vip-db-phpmyadmin.js +40 -39
- package/dist/bin/vip-db.js +13 -12
- package/dist/bin/vip-defensive-mode-configure.js +197 -197
- package/dist/bin/vip-defensive-mode-disable.js +43 -35
- package/dist/bin/vip-defensive-mode-enable.js +47 -38
- package/dist/bin/vip-defensive-mode.js +28 -17
- package/dist/bin/vip-dev-env-create.js +147 -104
- package/dist/bin/vip-dev-env-destroy.js +48 -39
- package/dist/bin/vip-dev-env-envvar-delete.js +60 -49
- package/dist/bin/vip-dev-env-envvar-get-all.js +52 -45
- package/dist/bin/vip-dev-env-envvar-get.js +48 -37
- package/dist/bin/vip-dev-env-envvar-list.js +48 -41
- package/dist/bin/vip-dev-env-envvar-set.js +83 -70
- package/dist/bin/vip-dev-env-envvar.js +38 -23
- package/dist/bin/vip-dev-env-exec.js +81 -74
- package/dist/bin/vip-dev-env-import-media.js +34 -26
- package/dist/bin/vip-dev-env-import-sql.js +65 -51
- package/dist/bin/vip-dev-env-import.js +23 -14
- package/dist/bin/vip-dev-env-info.js +59 -50
- package/dist/bin/vip-dev-env-list.js +34 -31
- package/dist/bin/vip-dev-env-logs.js +59 -49
- package/dist/bin/vip-dev-env-purge.js +71 -63
- package/dist/bin/vip-dev-env-shell.js +82 -71
- package/dist/bin/vip-dev-env-start.js +77 -65
- package/dist/bin/vip-dev-env-stop.js +80 -74
- package/dist/bin/vip-dev-env-sync-sql.js +80 -72
- package/dist/bin/vip-dev-env-sync.js +18 -11
- package/dist/bin/vip-dev-env-update.js +93 -84
- package/dist/bin/vip-dev-env.js +25 -8
- package/dist/bin/vip-edge-workers-build.js +82 -54
- package/dist/bin/vip-edge-workers-delete.js +84 -52
- package/dist/bin/vip-edge-workers-deploy.js +186 -126
- package/dist/bin/vip-edge-workers-disable.js +75 -44
- package/dist/bin/vip-edge-workers-enable.js +86 -54
- package/dist/bin/vip-edge-workers-get.js +108 -88
- package/dist/bin/vip-edge-workers-init.js +83 -53
- package/dist/bin/vip-edge-workers-list.js +89 -54
- package/dist/bin/vip-edge-workers-new.js +98 -69
- package/dist/bin/vip-edge-workers-validate.js +123 -82
- package/dist/bin/vip-edge-workers.js +19 -6
- package/dist/bin/vip-export-sql.js +75 -69
- package/dist/bin/vip-export.js +12 -7
- package/dist/bin/vip-import-media-abort.js +99 -73
- package/dist/bin/vip-import-media-status.js +83 -51
- package/dist/bin/vip-import-media.js +165 -166
- package/dist/bin/vip-import-sql-status.js +75 -45
- package/dist/bin/vip-import-sql.js +536 -596
- package/dist/bin/vip-import-validate-files.js +122 -141
- package/dist/bin/vip-import-validate-sql.js +52 -16
- package/dist/bin/vip-import.js +16 -7
- package/dist/bin/vip-logout.js +17 -13
- package/dist/bin/vip-logs.js +209 -183
- package/dist/bin/vip-search-replace.js +85 -53
- package/dist/bin/vip-slowlogs.js +168 -147
- package/dist/bin/vip-sync.js +163 -133
- package/dist/bin/vip-whoami.js +71 -35
- package/dist/bin/vip-wp.js +506 -549
- package/dist/bin/vip.js +161 -116
- package/dist/commands/backup-db.js +183 -149
- package/dist/commands/dev-env-import-sql.js +162 -117
- package/dist/commands/dev-env-sync-sql.js +372 -330
- package/dist/commands/export-sql.js +441 -425
- package/dist/commands/phpmyadmin.js +232 -212
- package/dist/commands/wp-ssh.js +218 -187
- package/dist/lib/analytics/clients/tracks.js +84 -91
- package/dist/lib/analytics/index.js +27 -27
- package/dist/lib/api/app.js +37 -36
- package/dist/lib/api/cache-purge.js +17 -20
- package/dist/lib/api/constants.js +5 -6
- package/dist/lib/api/edge-workers.js +84 -135
- package/dist/lib/api/error-debug.js +10 -13
- package/dist/lib/api/feature-flags.js +16 -17
- package/dist/lib/api/http.js +47 -48
- package/dist/lib/api/user.js +17 -18
- package/dist/lib/api.js +107 -116
- package/dist/lib/app-logs/app-logs.js +24 -25
- package/dist/lib/app-slowlogs/app-slowlogs.js +23 -24
- package/dist/lib/app-slowlogs/types.js +2 -1
- package/dist/lib/app.js +6 -8
- package/dist/lib/backup-storage-availability/backup-storage-availability.js +119 -119
- package/dist/lib/backup-storage-availability/docker-machine-not-found-error.js +5 -6
- package/dist/lib/cli/apiConfig.js +71 -41
- package/dist/lib/cli/command.js +1120 -873
- package/dist/lib/cli/config.js +29 -29
- package/dist/lib/cli/envAlias.js +35 -50
- package/dist/lib/cli/exit.js +19 -19
- package/dist/lib/cli/format.js +172 -172
- package/dist/lib/cli/progress.js +193 -236
- package/dist/lib/cli/prompt.js +14 -15
- package/dist/lib/cli/runtime-mode.js +5 -6
- package/dist/lib/client-file-uploader.js +489 -641
- package/dist/lib/config/software.js +206 -212
- package/dist/lib/constants/dev-environment.js +40 -37
- package/dist/lib/constants/file-size.js +6 -7
- package/dist/lib/constants/vipgo.js +24 -12
- package/dist/lib/custom-deploy/custom-deploy.js +138 -120
- package/dist/lib/database.js +88 -85
- package/dist/lib/defensive-mode/api.js +41 -46
- package/dist/lib/defensive-mode/cli-helpers.js +40 -40
- package/dist/lib/dev-environment/dev-environment-cli.js +776 -735
- package/dist/lib/dev-environment/dev-environment-configuration-file.js +224 -191
- package/dist/lib/dev-environment/dev-environment-core.js +697 -732
- package/dist/lib/dev-environment/dev-environment-database.js +57 -41
- package/dist/lib/dev-environment/dev-environment-lando.js +734 -666
- package/dist/lib/dev-environment/docker-utils.js +96 -90
- package/dist/lib/dev-environment/env-vars.js +61 -59
- package/dist/lib/dev-environment/lando-loader.js +6 -7
- package/dist/lib/dev-environment/types.js +2 -1
- package/dist/lib/edge-workers/confirmation.js +42 -36
- package/dist/lib/edge-workers/deployment.js +150 -159
- package/dist/lib/edge-workers/index.js +68 -85
- package/dist/lib/edge-workers/location.js +26 -26
- package/dist/lib/edge-workers/output.js +14 -15
- package/dist/lib/edge-workers/project.js +123 -132
- package/dist/lib/edge-workers/toolchains/assemblyscript/constants.js +6 -8
- package/dist/lib/edge-workers/toolchains/assemblyscript/index.js +100 -101
- package/dist/lib/edge-workers/toolchains/assemblyscript/templates.js +31 -33
- package/dist/lib/edge-workers/toolchains/index.js +15 -15
- package/dist/lib/edge-workers/types.js +10 -38
- package/dist/lib/edge-workers/validation.js +161 -150
- package/dist/lib/env.js +16 -17
- package/dist/lib/envvar/api-delete.js +16 -18
- package/dist/lib/envvar/api-get-all.js +15 -19
- package/dist/lib/envvar/api-get.js +8 -9
- package/dist/lib/envvar/api-list.js +16 -21
- package/dist/lib/envvar/api-set.js +20 -19
- package/dist/lib/envvar/api.js +34 -29
- package/dist/lib/envvar/input.js +29 -34
- package/dist/lib/envvar/logging.js +9 -11
- package/dist/lib/envvar/read-file.js +6 -7
- package/dist/lib/http/download-file.js +76 -44
- package/dist/lib/http/proxy-agent.js +37 -40
- package/dist/lib/http/proxy-dispatcher.js +69 -71
- package/dist/lib/keychain/insecure.js +40 -36
- package/dist/lib/keychain/keychain.js +2 -1
- package/dist/lib/keychain/secure.js +16 -15
- package/dist/lib/keychain.js +22 -22
- package/dist/lib/live-backup-copy.js +117 -115
- package/dist/lib/logout.js +17 -19
- package/dist/lib/media-import/config.js +15 -14
- package/dist/lib/media-import/media-file-import.js +9 -13
- package/dist/lib/media-import/progress.js +53 -65
- package/dist/lib/media-import/status.js +241 -256
- package/dist/lib/media-import/utils.js +15 -15
- package/dist/lib/node-version-check.js +16 -16
- package/dist/lib/promise.js +16 -17
- package/dist/lib/read-file.js +48 -16
- package/dist/lib/rechallenge/client.js +37 -43
- package/dist/lib/rechallenge/errors.js +38 -37
- package/dist/lib/rechallenge/flow.js +148 -123
- package/dist/lib/rechallenge/index.js +23 -24
- package/dist/lib/rechallenge/link.js +153 -151
- package/dist/lib/rechallenge/open-browser.js +14 -17
- package/dist/lib/rechallenge/token-cache.js +83 -86
- package/dist/lib/rechallenge/types.js +5 -14
- package/dist/lib/retry.js +93 -129
- package/dist/lib/search-and-replace.js +164 -148
- package/dist/lib/site-import/db-file-import.js +12 -16
- package/dist/lib/site-import/status.js +291 -291
- package/dist/lib/token.js +86 -87
- package/dist/lib/tracker.js +51 -62
- package/dist/lib/types/graphql/rate-limit-exceeded-error.js +2 -1
- package/dist/lib/types.js +2 -1
- package/dist/lib/user-error.js +6 -8
- package/dist/lib/utils.js +81 -87
- package/dist/lib/validations/custom-deploy.js +218 -186
- package/dist/lib/validations/is-multi-site-sql-dump.js +6 -6
- package/dist/lib/validations/is-multi-site.js +83 -50
- package/dist/lib/validations/is-multisite-domain-mapped.js +92 -62
- package/dist/lib/validations/line-by-line.js +78 -46
- package/dist/lib/validations/site-type.js +59 -63
- package/dist/lib/validations/sql-insert-parser.js +415 -0
- package/dist/lib/validations/sql.js +551 -431
- package/dist/lib/validations/utils.js +27 -29
- package/dist/lib/vip-import-validate-files.js +481 -490
- package/dist/lib/wp/helpers.js +41 -45
- package/dist/lib/wp/readline.js +21 -57
- package/dist/lib/xdg-data.js +11 -12
- package/helpers/mark-cli-executable.js +9 -0
- package/node_modules/@apollo/client/CHANGELOG.md +10 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/helpers.cjs +5 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/helpers.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/inMemoryCache.cjs +2 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/key-extractor.cjs +14 -2
- package/node_modules/@apollo/client/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.cjs +16 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.d.cts +2 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/writeToStore.cjs +3 -2
- package/node_modules/@apollo/client/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/core/QueryInfo.cjs +9 -1
- package/node_modules/@apollo/client/__cjs/core/QueryInfo.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/core/QueryInfo.d.cts +1 -1
- package/node_modules/@apollo/client/__cjs/core/QueryManager.cjs +10 -3
- package/node_modules/@apollo/client/__cjs/core/QueryManager.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/react/hooks/useFragment.d.cts +42 -43
- package/node_modules/@apollo/client/__cjs/version.cjs +1 -1
- package/node_modules/@apollo/client/cache/inmemory/helpers.js +5 -0
- package/node_modules/@apollo/client/cache/inmemory/helpers.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/inMemoryCache.js +2 -1
- package/node_modules/@apollo/client/cache/inmemory/inMemoryCache.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/key-extractor.js +14 -2
- package/node_modules/@apollo/client/cache/inmemory/key-extractor.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/policies.d.ts +2 -0
- package/node_modules/@apollo/client/cache/inmemory/policies.js +17 -1
- package/node_modules/@apollo/client/cache/inmemory/policies.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/writeToStore.js +3 -2
- package/node_modules/@apollo/client/cache/inmemory/writeToStore.js.map +1 -1
- package/node_modules/@apollo/client/core/QueryInfo.d.ts +1 -1
- package/node_modules/@apollo/client/core/QueryInfo.js +10 -2
- package/node_modules/@apollo/client/core/QueryInfo.js.map +1 -1
- package/node_modules/@apollo/client/core/QueryManager.js +10 -3
- package/node_modules/@apollo/client/core/QueryManager.js.map +1 -1
- package/node_modules/@apollo/client/package.json +1 -1
- package/node_modules/@apollo/client/react/hooks/useFragment.d.ts +42 -43
- package/node_modules/@apollo/client/react/hooks/useFragment.js.map +1 -1
- package/node_modules/@apollo/client/react/hooks-compiled/useFragment.d.ts +42 -43
- package/node_modules/@apollo/client/react/hooks-compiled/useFragment.js.map +1 -1
- package/node_modules/@apollo/client/version.js +1 -1
- package/node_modules/@automattic/vip-search-replace/README.md +6 -1
- package/node_modules/@automattic/vip-search-replace/lib/index.js +46 -14
- package/node_modules/@automattic/vip-search-replace/package.json +1 -1
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/zlib.d.ts +752 -0
- package/node_modules/check-disk-space/README.md +92 -32
- package/node_modules/check-disk-space/dist/check-disk-space.d.mts +58 -0
- package/node_modules/check-disk-space/dist/check-disk-space.mjs +170 -190
- package/node_modules/check-disk-space/package.json +43 -71
- package/node_modules/cpu-features/build/Makefile +2 -2
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/filesystem.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_windows.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_arm_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_mips_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_ppc_linux.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_freebsd.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_macos.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_windows.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/stack_line_reader.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/string_view.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpufeatures/src/binding.o.d +157 -145
- package/node_modules/cpu-features/build/Release/cpufeatures.node +0 -0
- package/node_modules/cpu-features/build/Release/obj.target/cpufeatures/src/binding.o +0 -0
- package/node_modules/cpu-features/build/Release/obj.target/cpufeatures.node +0 -0
- package/node_modules/cpu-features/build/config.gypi +100 -31
- package/node_modules/cpu-features/build/cpufeatures.target.mk +14 -14
- package/node_modules/cpu-features/build/deps/cpu_features/cpu_features.target.mk +14 -14
- package/node_modules/ssh2/lib/protocol/crypto/build/Makefile +2 -2
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto/src/binding.o.d.raw +136 -0
- package/node_modules/ssh2/lib/protocol/crypto/build/sshcrypto.target.mk +14 -14
- package/node_modules/undici/docs/docs/api/Interceptors.md +15 -2
- package/node_modules/undici/lib/dispatcher/client-h2.js +78 -3
- package/node_modules/undici/lib/dispatcher/pool-base.js +20 -3
- package/node_modules/undici/package.json +3 -3
- package/node_modules/undici/types/api.d.ts +1 -1
- package/node_modules/undici/types/utility.d.ts +4 -4
- package/package.json +44 -13
- package/dist/lib/analytics/clients/client.js +0 -1
- package/dist/lib/analytics/clients/pendo.js +0 -78
- package/helpers/check-version.js +0 -16
- package/node_modules/check-disk-space/dist/check-disk-space.cjs +0 -210
- package/node_modules/check-disk-space/dist/check-disk-space.d.ts +0 -53
- package/node_modules/fetch-retry/.eslintignore +0 -1
- package/node_modules/fetch-retry/.eslintrc.yml +0 -20
- package/node_modules/fetch-retry/.github/workflows/node.js.yml +0 -32
- package/node_modules/fetch-retry/.husky/pre-commit +0 -6
- package/node_modules/fetch-retry/.nycrc.json +0 -24
- package/node_modules/fetch-retry/.travis.yml +0 -3
- package/node_modules/fetch-retry/LICENSE +0 -21
- package/node_modules/fetch-retry/README.md +0 -128
- package/node_modules/fetch-retry/dist/fetch-retry.umd.js +0 -151
- package/node_modules/fetch-retry/index.d.ts +0 -29
- package/node_modules/fetch-retry/index.js +0 -143
- package/node_modules/fetch-retry/package.json +0 -41
- package/node_modules/fetch-retry/rollup.config.js +0 -12
- package/node_modules/fetch-retry/test/.eslintrc.yml +0 -7
- package/node_modules/fetch-retry/test/integration/index.js +0 -212
- package/node_modules/fetch-retry/test/integration/mock-api/index.js +0 -42
- package/node_modules/fetch-retry/test/unit/index.js +0 -1169
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto/src/binding.o.d +0 -265
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto.node.d +0 -1
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/sshcrypto.node.d +0 -1
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/obj.target/sshcrypto/src/binding.o +0 -0
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/obj.target/sshcrypto.node +0 -0
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node +0 -0
|
@@ -1,28 +1,60 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
40
|
exports.DevEnvSyncSQLCommand = void 0;
|
|
6
41
|
exports.findSiteHomeUrl = findSiteHomeUrl;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
|
-
const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
|
|
25
|
-
|
|
42
|
+
const vip_search_replace_1 = require("@automattic/vip-search-replace");
|
|
43
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
44
|
+
const debug_1 = __importDefault(require("debug"));
|
|
45
|
+
const fs_1 = __importDefault(require("fs"));
|
|
46
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
47
|
+
const promises_1 = require("node:stream/promises");
|
|
48
|
+
const dev_env_import_sql_1 = require("./dev-env-import-sql");
|
|
49
|
+
const export_sql_1 = require("./export-sql");
|
|
50
|
+
const api_1 = __importDefault(require("../lib/api"));
|
|
51
|
+
const backup_storage_availability_1 = require("../lib/backup-storage-availability/backup-storage-availability");
|
|
52
|
+
const exit = __importStar(require("../lib/cli/exit"));
|
|
53
|
+
const client_file_uploader_1 = require("../lib/client-file-uploader");
|
|
54
|
+
const database_1 = require("../lib/database");
|
|
55
|
+
const utils_1 = require("../lib/utils");
|
|
56
|
+
const line_by_line_1 = require("../lib/validations/line-by-line");
|
|
57
|
+
const debug = (0, debug_1.default)('@automattic/vip:bin:dev-environment');
|
|
26
58
|
/**
|
|
27
59
|
* Replaces the domain in the given URL
|
|
28
60
|
*
|
|
@@ -31,7 +63,6 @@ const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
|
|
|
31
63
|
* @return The URL with the new domain
|
|
32
64
|
*/
|
|
33
65
|
const replaceDomain = (str, domain) => str.replace(/^([^:]+:\/\/)([^:/]+)/, `$1${domain}`);
|
|
34
|
-
|
|
35
66
|
/**
|
|
36
67
|
* Strips the protocol from the URL
|
|
37
68
|
*
|
|
@@ -39,10 +70,9 @@ const replaceDomain = (str, domain) => str.replace(/^([^:]+:\/\/)([^:/]+)/, `$1$
|
|
|
39
70
|
* @return The URL without the protocol
|
|
40
71
|
*/
|
|
41
72
|
function stripProtocol(url) {
|
|
42
|
-
|
|
43
|
-
|
|
73
|
+
const parts = url.split('//', 2);
|
|
74
|
+
return parts.length > 1 ? parts[1] : parts[0];
|
|
44
75
|
}
|
|
45
|
-
|
|
46
76
|
/**
|
|
47
77
|
* Finds the site home url from the SQL line
|
|
48
78
|
*
|
|
@@ -50,16 +80,16 @@ function stripProtocol(url) {
|
|
|
50
80
|
* @return Site home url. null if not found
|
|
51
81
|
*/
|
|
52
82
|
function findSiteHomeUrl(sql) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
83
|
+
const regex = /(['"])(?:siteurl|home)\1,\s*\1([Hh][Tt][Tt][Pp][Ss]?:\/\/.+?)\1/;
|
|
84
|
+
const url = regex.exec(sql)?.[2] ?? '';
|
|
85
|
+
try {
|
|
86
|
+
const parsed = new URL(url);
|
|
87
|
+
return parsed.hostname ? url : null;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
61
92
|
}
|
|
62
|
-
|
|
63
93
|
/**
|
|
64
94
|
* Extracts a list of site urls from the SQL file
|
|
65
95
|
*
|
|
@@ -68,24 +98,24 @@ function findSiteHomeUrl(sql) {
|
|
|
68
98
|
* @throws {Error} If there is an error reading the file
|
|
69
99
|
*/
|
|
70
100
|
async function extractSiteUrls(sqlFile) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
101
|
+
const readInterface = await (0, line_by_line_1.getReadInterface)(sqlFile);
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
const urls = new Set();
|
|
104
|
+
readInterface.on('line', line => {
|
|
105
|
+
let url = findSiteHomeUrl(line);
|
|
106
|
+
if (url) {
|
|
107
|
+
url = url.replace(/\/$/, '');
|
|
108
|
+
urls.add(url);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
readInterface.on('close', () => {
|
|
112
|
+
// Soring by length so that longest URLs are replaced first
|
|
113
|
+
resolve(Array.from(urls).sort((url1, url2) => url2.length - url1.length));
|
|
114
|
+
});
|
|
115
|
+
readInterface.on('error', reject);
|
|
80
116
|
});
|
|
81
|
-
readInterface.on('close', () => {
|
|
82
|
-
// Soring by length so that longest URLs are replaced first
|
|
83
|
-
resolve(Array.from(urls).sort((url1, url2) => url2.length - url1.length));
|
|
84
|
-
});
|
|
85
|
-
readInterface.on('error', reject);
|
|
86
|
-
});
|
|
87
117
|
}
|
|
88
|
-
const SITE_URLS_QUERY = (0,
|
|
118
|
+
const SITE_URLS_QUERY = (0, graphql_tag_1.default) `
|
|
89
119
|
query SiteUrlsQuery($appId: Int!, $environmentId: Int!, $after: String, $first: Int!) {
|
|
90
120
|
app(id: $appId) {
|
|
91
121
|
environments(id: $environmentId) {
|
|
@@ -104,304 +134,316 @@ const SITE_URLS_QUERY = (0, _graphqlTag.default)`
|
|
|
104
134
|
}
|
|
105
135
|
`;
|
|
106
136
|
class DevEnvSyncSQLCommand {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
...eventProps,
|
|
130
|
-
sqldump_type: this._sqlDumpType,
|
|
131
|
-
live_backup_copy: this.liveBackupCopyCLIOptions?.useLiveBackupCopy
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
get landoDomain() {
|
|
135
|
-
return `${this.slug}.${this.lando.config.domain}`;
|
|
136
|
-
}
|
|
137
|
-
get sqlFile() {
|
|
138
|
-
return `${this.tmpDir}/sql-export.sql`;
|
|
139
|
-
}
|
|
140
|
-
get gzFile() {
|
|
141
|
-
return `${this.tmpDir}/sql-export.sql.gz`;
|
|
142
|
-
}
|
|
143
|
-
getSqlDumpType() {
|
|
144
|
-
if (!this._sqlDumpType) {
|
|
145
|
-
throw new Error('SQL Dump type not initialized');
|
|
137
|
+
app;
|
|
138
|
+
env;
|
|
139
|
+
slug;
|
|
140
|
+
lando;
|
|
141
|
+
tmpDir;
|
|
142
|
+
siteUrls = [];
|
|
143
|
+
searchReplaceMap = {};
|
|
144
|
+
liveBackupCopyCLIOptions;
|
|
145
|
+
_track;
|
|
146
|
+
_sqlDumpType;
|
|
147
|
+
sdsSiteUrls = [];
|
|
148
|
+
/**
|
|
149
|
+
* Creates a new instance of the command
|
|
150
|
+
*/
|
|
151
|
+
constructor(app, env, slug, lando, trackerFn = () => { }, liveBackupCopyCLIOptions) {
|
|
152
|
+
this.app = app;
|
|
153
|
+
this.env = env;
|
|
154
|
+
this.slug = slug;
|
|
155
|
+
this.lando = lando;
|
|
156
|
+
this._track = trackerFn;
|
|
157
|
+
this.tmpDir = (0, utils_1.makeTempDir)();
|
|
158
|
+
this.liveBackupCopyCLIOptions = liveBackupCopyCLIOptions;
|
|
146
159
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
async confirmEnoughStorage(archiveSize) {
|
|
154
|
-
const storageAvailability = new _backupStorageAvailability.BackupStorageAvailability();
|
|
155
|
-
return await storageAvailability.validateAndPromptDiskSpaceWarningForDevEnvBackupImport(archiveSize);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Runs the SQL export command to generate the SQL export from
|
|
160
|
-
* the latest backup
|
|
161
|
-
*/
|
|
162
|
-
async generateExport() {
|
|
163
|
-
const exportCommand = new _exportSql.ExportSQLCommand(this.app, this.env, {
|
|
164
|
-
outputFile: this.gzFile,
|
|
165
|
-
confirmEnoughStorageHook: this.confirmEnoughStorage.bind(this),
|
|
166
|
-
liveBackupCopyCLIOptions: this.liveBackupCopyCLIOptions
|
|
167
|
-
}, this.track.bind(this));
|
|
168
|
-
await exportCommand.run();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Runs the search-replace operation on the SQL file
|
|
173
|
-
* to replace the site urls with the lando domain
|
|
174
|
-
*
|
|
175
|
-
* @return {Promise<void>} Promise that resolves when the search-replace is complete
|
|
176
|
-
* @throws {Error} If there is an error reading the file
|
|
177
|
-
*/
|
|
178
|
-
async runSearchReplace() {
|
|
179
|
-
const replacements = Object.entries(this.searchReplaceMap).flat();
|
|
180
|
-
const readStream = _fs.default.createReadStream(this.sqlFile);
|
|
181
|
-
const replacedStream = await (0, _vipSearchReplace.replace)(readStream, replacements);
|
|
182
|
-
const outputFile = `${this.tmpDir}/sql-export-sr.sql`;
|
|
183
|
-
const transforms = [];
|
|
184
|
-
if (this.getSqlDumpType() === _database.SqlDumpType.MYDUMPER) {
|
|
185
|
-
transforms.push((0, _database.fixMyDumperTransform)());
|
|
160
|
+
track(name, eventProps) {
|
|
161
|
+
return this._track(name, {
|
|
162
|
+
...eventProps,
|
|
163
|
+
sqldump_type: this._sqlDumpType,
|
|
164
|
+
live_backup_copy: this.liveBackupCopyCLIOptions?.useLiveBackupCopy,
|
|
165
|
+
});
|
|
186
166
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
getSiteUrlsFromSDS() {
|
|
191
|
-
if (this.env.isMultisite) {
|
|
192
|
-
return this.fetchAllSites(Number(this.app.id), Number(this.env.id));
|
|
167
|
+
get landoDomain() {
|
|
168
|
+
return `${this.slug}.${this.lando.config.domain}`;
|
|
193
169
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
fetchSitesPage(api, appId, environmentId, after) {
|
|
197
|
-
return api.query({
|
|
198
|
-
query: SITE_URLS_QUERY,
|
|
199
|
-
variables: {
|
|
200
|
-
first: 100,
|
|
201
|
-
after,
|
|
202
|
-
appId,
|
|
203
|
-
environmentId
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
async fetchAllSites(appId, environmentId) {
|
|
208
|
-
const api = (0, _api.default)();
|
|
209
|
-
let after = null;
|
|
210
|
-
const allSites = [];
|
|
211
|
-
let total;
|
|
212
|
-
console.log('Fetching list of sites for database sync...');
|
|
213
|
-
do {
|
|
214
|
-
// eslint-disable-next-line no-await-in-loop
|
|
215
|
-
const res = await this.fetchSitesPage(api, appId, environmentId, after);
|
|
216
|
-
if (res.data?.app?.environments?.[0]?.wpSitesSDS?.nodes) {
|
|
217
|
-
const wpSitesSDS = res.data.app.environments[0].wpSitesSDS;
|
|
218
|
-
allSites.push(...res.data.app.environments[0].wpSitesSDS.nodes.filter(node => Boolean(node)));
|
|
219
|
-
after = wpSitesSDS.nextCursor;
|
|
220
|
-
total = Number(wpSitesSDS.total);
|
|
221
|
-
console.log(`Fetched ${allSites.length} of ${total} sites...`);
|
|
222
|
-
} else {
|
|
223
|
-
after = null;
|
|
224
|
-
}
|
|
225
|
-
} while (after);
|
|
226
|
-
return allSites;
|
|
227
|
-
}
|
|
228
|
-
generateSearchReplaceMap() {
|
|
229
|
-
this.searchReplaceMap = {};
|
|
230
|
-
for (const url of this.siteUrls) {
|
|
231
|
-
this.searchReplaceMap[stripProtocol(url)] = stripProtocol(replaceDomain(url, this.landoDomain));
|
|
170
|
+
get sqlFile() {
|
|
171
|
+
return `${this.tmpDir}/sql-export.sql`;
|
|
232
172
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const primaryUrl = networkSites.find(site => site?.blogId === 1)?.homeUrl;
|
|
236
|
-
const primaryDomain = primaryUrl ? new URL(primaryUrl).hostname : '';
|
|
237
|
-
debug('Network sites: %j, primary URL: %s, primary domain: %s', networkSites.map(site => ({
|
|
238
|
-
blogId: site?.blogId,
|
|
239
|
-
homeUrl: site?.homeUrl
|
|
240
|
-
})), primaryUrl, primaryDomain);
|
|
241
|
-
for (const site of networkSites) {
|
|
242
|
-
if (!site?.blogId || site.blogId === 1) continue;
|
|
243
|
-
const url = site?.homeUrl;
|
|
244
|
-
if (!url) continue;
|
|
245
|
-
const strippedUrl = stripProtocol(url).replace(/\/$/, '');
|
|
246
|
-
if (!this.searchReplaceMap[strippedUrl]) continue;
|
|
247
|
-
const domain = new URL(url).hostname;
|
|
248
|
-
const newDomain = primaryDomain === domain ? this.landoDomain : `${this.slugifyDomain(domain)}.${this.landoDomain}`;
|
|
249
|
-
this.searchReplaceMap[stripProtocol(url)] = stripProtocol(replaceDomain(url, newDomain));
|
|
173
|
+
get gzFile() {
|
|
174
|
+
return `${this.tmpDir}/sql-export.sql.gz`;
|
|
250
175
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
176
|
+
getSqlDumpType() {
|
|
177
|
+
if (!this._sqlDumpType) {
|
|
178
|
+
throw new Error('SQL Dump type not initialized');
|
|
179
|
+
}
|
|
180
|
+
return this._sqlDumpType;
|
|
181
|
+
}
|
|
182
|
+
async initSqlDumpType() {
|
|
183
|
+
const dumpDetails = await (0, database_1.getSqlDumpDetails)(this.sqlFile);
|
|
184
|
+
this._sqlDumpType = dumpDetails.type;
|
|
185
|
+
}
|
|
186
|
+
async confirmEnoughStorage(archiveSize) {
|
|
187
|
+
const storageAvailability = new backup_storage_availability_1.BackupStorageAvailability();
|
|
188
|
+
return await storageAvailability.validateAndPromptDiskSpaceWarningForDevEnvBackupImport(archiveSize);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Runs the SQL export command to generate the SQL export from
|
|
192
|
+
* the latest backup
|
|
193
|
+
*/
|
|
194
|
+
async generateExport() {
|
|
195
|
+
const exportCommand = new export_sql_1.ExportSQLCommand(this.app, this.env, {
|
|
196
|
+
outputFile: this.gzFile,
|
|
197
|
+
confirmEnoughStorageHook: this.confirmEnoughStorage.bind(this),
|
|
198
|
+
liveBackupCopyCLIOptions: this.liveBackupCopyCLIOptions,
|
|
199
|
+
}, this.track.bind(this));
|
|
200
|
+
await exportCommand.run();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Runs the search-replace operation on the SQL file
|
|
204
|
+
* to replace the site urls with the lando domain
|
|
205
|
+
*
|
|
206
|
+
* @return {Promise<void>} Promise that resolves when the search-replace is complete
|
|
207
|
+
* @throws {Error} If there is an error reading the file
|
|
208
|
+
*/
|
|
209
|
+
async runSearchReplace() {
|
|
210
|
+
const replacements = Object.entries(this.searchReplaceMap).flat();
|
|
211
|
+
const readStream = fs_1.default.createReadStream(this.sqlFile);
|
|
212
|
+
const replacedStream = await (0, vip_search_replace_1.replace)(readStream, replacements);
|
|
213
|
+
const outputFile = `${this.tmpDir}/sql-export-sr.sql`;
|
|
214
|
+
const transforms = [];
|
|
215
|
+
if (this.getSqlDumpType() === database_1.SqlDumpType.MYDUMPER) {
|
|
216
|
+
transforms.push((0, database_1.fixMyDumperTransform)());
|
|
217
|
+
}
|
|
218
|
+
await (0, promises_1.pipeline)(replacedStream, ...transforms, fs_1.default.createWriteStream(outputFile));
|
|
219
|
+
fs_1.default.renameSync(outputFile, this.sqlFile);
|
|
220
|
+
}
|
|
221
|
+
getSiteUrlsFromSDS() {
|
|
222
|
+
if (this.env.isMultisite) {
|
|
223
|
+
return this.fetchAllSites(Number(this.app.id), Number(this.env.id));
|
|
224
|
+
}
|
|
225
|
+
return Promise.resolve([]);
|
|
226
|
+
}
|
|
227
|
+
fetchSitesPage(api, appId, environmentId, after) {
|
|
228
|
+
return api.query({
|
|
229
|
+
query: SITE_URLS_QUERY,
|
|
230
|
+
variables: {
|
|
231
|
+
first: 100,
|
|
232
|
+
after,
|
|
233
|
+
appId,
|
|
234
|
+
environmentId,
|
|
235
|
+
},
|
|
236
|
+
});
|
|
282
237
|
}
|
|
283
|
-
|
|
238
|
+
async fetchAllSites(appId, environmentId) {
|
|
239
|
+
const api = (0, api_1.default)();
|
|
240
|
+
let after = null;
|
|
241
|
+
const allSites = [];
|
|
242
|
+
let total;
|
|
243
|
+
console.log('Fetching list of sites for database sync...');
|
|
244
|
+
do {
|
|
245
|
+
// eslint-disable-next-line no-await-in-loop
|
|
246
|
+
const res = await this.fetchSitesPage(api, appId, environmentId, after);
|
|
247
|
+
if (res.data?.app?.environments?.[0]?.wpSitesSDS?.nodes) {
|
|
248
|
+
const wpSitesSDS = res.data.app.environments[0].wpSitesSDS;
|
|
249
|
+
allSites.push(...res.data.app.environments[0].wpSitesSDS.nodes.filter((node) => Boolean(node)));
|
|
250
|
+
after = wpSitesSDS.nextCursor;
|
|
251
|
+
total = Number(wpSitesSDS.total);
|
|
252
|
+
console.log(`Fetched ${allSites.length} of ${total} sites...`);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
after = null;
|
|
256
|
+
}
|
|
257
|
+
} while (after);
|
|
258
|
+
return allSites;
|
|
259
|
+
}
|
|
260
|
+
generateSearchReplaceMap() {
|
|
261
|
+
this.searchReplaceMap = {};
|
|
262
|
+
for (const url of this.siteUrls) {
|
|
263
|
+
this.searchReplaceMap[stripProtocol(url)] = stripProtocol(replaceDomain(url, this.landoDomain));
|
|
264
|
+
}
|
|
265
|
+
const networkSites = this.sdsSiteUrls;
|
|
266
|
+
if (!networkSites.length)
|
|
267
|
+
return;
|
|
268
|
+
const primaryUrl = networkSites.find(site => site?.blogId === 1)?.homeUrl;
|
|
269
|
+
const primaryDomain = primaryUrl ? new URL(primaryUrl).hostname : '';
|
|
270
|
+
debug('Network sites: %j, primary URL: %s, primary domain: %s', networkSites.map(site => ({ blogId: site?.blogId, homeUrl: site?.homeUrl })), primaryUrl, primaryDomain);
|
|
271
|
+
for (const site of networkSites) {
|
|
272
|
+
if (!site?.blogId || site.blogId === 1)
|
|
273
|
+
continue;
|
|
274
|
+
const url = site?.homeUrl;
|
|
275
|
+
if (!url)
|
|
276
|
+
continue;
|
|
277
|
+
const strippedUrl = stripProtocol(url).replace(/\/$/, '');
|
|
278
|
+
if (!this.searchReplaceMap[strippedUrl])
|
|
279
|
+
continue;
|
|
280
|
+
const domain = new URL(url).hostname;
|
|
281
|
+
const newDomain = primaryDomain === domain
|
|
282
|
+
? this.landoDomain
|
|
283
|
+
: `${this.slugifyDomain(domain)}.${this.landoDomain}`;
|
|
284
|
+
this.searchReplaceMap[stripProtocol(url)] = stripProtocol(replaceDomain(url, newDomain));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
slugifyDomain(domain) {
|
|
288
|
+
return String(domain)
|
|
289
|
+
.normalize('NFKD') // split accented characters into their base characters and diacritical marks
|
|
290
|
+
.replace(/[\u0300-\u036f]/g, '') // remove all the accents, which happen to be all in the \u03xx UNICODE block.
|
|
291
|
+
.trim() // trim leading or trailing whitespace
|
|
292
|
+
.toLowerCase() // convert to lowercase
|
|
293
|
+
.replace(/[^a-z0-9 .-]/g, '') // remove non-alphanumeric characters except for spaces, dots, and hyphens
|
|
294
|
+
.replace(/[.\s]+/g, '-') // replace dots and spaces with hyphens
|
|
295
|
+
.replace(/-+/g, '-'); // remove consecutive hyphens
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Runs the SQL import command to import the SQL file
|
|
299
|
+
*
|
|
300
|
+
* @return {Promise<void>} Promise that resolves when the import is complete
|
|
301
|
+
* @throws {Error} If there is an error importing the file
|
|
302
|
+
*/
|
|
303
|
+
async runImport() {
|
|
304
|
+
const importOptions = {
|
|
305
|
+
inPlace: true,
|
|
306
|
+
skipValidate: true,
|
|
307
|
+
quiet: true,
|
|
308
|
+
postImportSQL: this.fixBlogsTableQuery(),
|
|
309
|
+
};
|
|
310
|
+
const importCommand = new dev_env_import_sql_1.DevEnvImportSQLCommand(this.sqlFile, importOptions, this.slug);
|
|
311
|
+
await importCommand.run();
|
|
312
|
+
}
|
|
313
|
+
fixBlogsTableQuery() {
|
|
314
|
+
const networkSites = this.sdsSiteUrls;
|
|
315
|
+
if (!networkSites.length) {
|
|
316
|
+
return '';
|
|
317
|
+
}
|
|
318
|
+
const prologue = `
|
|
284
319
|
DROP PROCEDURE IF EXISTS vip_sync_update_blog_domains;
|
|
285
320
|
DELIMITER $$
|
|
286
321
|
CREATE PROCEDURE vip_sync_update_blog_domains()
|
|
287
322
|
BEGIN
|
|
288
323
|
IF EXISTS (SELECT * FROM information_schema.tables WHERE table_schema = 'wordpress' AND table_name = 'wp_blogs') THEN
|
|
289
324
|
`;
|
|
290
|
-
|
|
325
|
+
const epilogue = `
|
|
291
326
|
END IF;
|
|
292
327
|
END$$
|
|
293
328
|
DELIMITER ;
|
|
294
329
|
CALL vip_sync_update_blog_domains();
|
|
295
330
|
DROP PROCEDURE vip_sync_update_blog_domains;
|
|
296
331
|
`;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Sequentially runs the commands to export, search-replace, and import the SQL file
|
|
316
|
-
* to the local environment
|
|
317
|
-
*
|
|
318
|
-
* @return Promise that resolves to true when the commands are complete. It will return false if the user did not continue during validation prompts.
|
|
319
|
-
*/
|
|
320
|
-
async run() {
|
|
321
|
-
try {
|
|
322
|
-
await this.generateExport();
|
|
323
|
-
} catch (err) {
|
|
324
|
-
const error = err;
|
|
325
|
-
// this.generateExport probably catches all exceptions, track the event and runs exit.withError() but if things go really wrong
|
|
326
|
-
// and we have no tracking data, we would at least have it logged here.
|
|
327
|
-
// the following will not get executed if this.generateExport() calls exit.withError() on all exception
|
|
328
|
-
await this.track('error', {
|
|
329
|
-
error_type: 'export_sql_backup',
|
|
330
|
-
error_message: error.message,
|
|
331
|
-
stack: error.stack
|
|
332
|
-
});
|
|
333
|
-
exit.withError(`Error exporting SQL backup: ${error.message}`);
|
|
334
|
-
}
|
|
335
|
-
try {
|
|
336
|
-
console.log(`Extracting the exported file ${this.gzFile}...`);
|
|
337
|
-
await (0, _clientFileUploader.unzipFile)(this.gzFile, this.sqlFile);
|
|
338
|
-
await this.initSqlDumpType();
|
|
339
|
-
console.log(`${_chalk.default.green('✓')} Extracted to ${this.sqlFile}`);
|
|
340
|
-
} catch (err) {
|
|
341
|
-
const error = err;
|
|
342
|
-
await this.track('error', {
|
|
343
|
-
error_type: 'archive_extraction',
|
|
344
|
-
error_message: error.message,
|
|
345
|
-
stack: error.stack
|
|
346
|
-
});
|
|
347
|
-
exit.withError(`Error extracting the SQL export: ${error.message}`);
|
|
348
|
-
}
|
|
349
|
-
try {
|
|
350
|
-
console.log('Extracting site urls from the SQL file...');
|
|
351
|
-
this.siteUrls = await extractSiteUrls(this.sqlFile);
|
|
352
|
-
debug('Extracted site URLs: %j', this.siteUrls);
|
|
353
|
-
} catch (err) {
|
|
354
|
-
const error = err;
|
|
355
|
-
await this.track('error', {
|
|
356
|
-
error_type: 'extract_site_urls',
|
|
357
|
-
error_message: error.message,
|
|
358
|
-
stack: error.stack
|
|
359
|
-
});
|
|
360
|
-
exit.withError(`Error extracting site URLs: ${error.message}`);
|
|
361
|
-
}
|
|
362
|
-
try {
|
|
363
|
-
this.sdsSiteUrls = await this.getSiteUrlsFromSDS();
|
|
364
|
-
} catch (err) {
|
|
365
|
-
const error = err;
|
|
366
|
-
await this.track('error', {
|
|
367
|
-
error_type: 'get_site_urls_from_sds',
|
|
368
|
-
error_message: error.message,
|
|
369
|
-
stack: error.stack
|
|
370
|
-
});
|
|
371
|
-
exit.withError(`Error getting site URLs from SDS: ${error.message}`);
|
|
372
|
-
}
|
|
373
|
-
console.log('Generating search-replace configuration...');
|
|
374
|
-
this.generateSearchReplaceMap();
|
|
375
|
-
try {
|
|
376
|
-
console.log('Running the following search-replace operations on the SQL file:');
|
|
377
|
-
for (const [domain, landoDomain] of Object.entries(this.searchReplaceMap)) {
|
|
378
|
-
console.log(` ${domain} -> ${landoDomain}`);
|
|
379
|
-
}
|
|
380
|
-
await this.runSearchReplace();
|
|
381
|
-
console.log(`${_chalk.default.green('✓')} Search-replace operation is complete`);
|
|
382
|
-
} catch (err) {
|
|
383
|
-
const error = err;
|
|
384
|
-
await this.track('error', {
|
|
385
|
-
error_type: 'search_replace',
|
|
386
|
-
error_message: error.message,
|
|
387
|
-
stack: error.stack
|
|
388
|
-
});
|
|
389
|
-
exit.withError(`Error replacing domains: ${error.message}`);
|
|
332
|
+
const primaryUrl = networkSites.find(site => site?.blogId === 1)?.homeUrl;
|
|
333
|
+
const primaryDomain = primaryUrl ? new URL(primaryUrl).hostname : '';
|
|
334
|
+
const queries = [];
|
|
335
|
+
for (const site of networkSites) {
|
|
336
|
+
if (!site?.blogId || !site?.homeUrl) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const oldDomain = new URL(site.homeUrl).hostname;
|
|
340
|
+
const newDomain = primaryDomain !== oldDomain
|
|
341
|
+
? `${this.slugifyDomain(oldDomain)}.${this.landoDomain}`
|
|
342
|
+
: this.landoDomain;
|
|
343
|
+
queries.push(` UPDATE wp_blogs SET domain = '${newDomain}' WHERE blog_id = ${Number(site.blogId)};`);
|
|
344
|
+
}
|
|
345
|
+
if (queries.length === 0) {
|
|
346
|
+
return '';
|
|
347
|
+
}
|
|
348
|
+
return `${prologue}\n${queries.join('\n')}\n${epilogue}`;
|
|
390
349
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
350
|
+
/**
|
|
351
|
+
* Sequentially runs the commands to export, search-replace, and import the SQL file
|
|
352
|
+
* to the local environment
|
|
353
|
+
*
|
|
354
|
+
* @return Promise that resolves to true when the commands are complete. It will return false if the user did not continue during validation prompts.
|
|
355
|
+
*/
|
|
356
|
+
async run() {
|
|
357
|
+
try {
|
|
358
|
+
await this.generateExport();
|
|
359
|
+
}
|
|
360
|
+
catch (err) {
|
|
361
|
+
const error = err;
|
|
362
|
+
// this.generateExport probably catches all exceptions, track the event and runs exit.withError() but if things go really wrong
|
|
363
|
+
// and we have no tracking data, we would at least have it logged here.
|
|
364
|
+
// the following will not get executed if this.generateExport() calls exit.withError() on all exception
|
|
365
|
+
await this.track('error', {
|
|
366
|
+
error_type: 'export_sql_backup',
|
|
367
|
+
error_message: error.message,
|
|
368
|
+
stack: error.stack,
|
|
369
|
+
});
|
|
370
|
+
exit.withError(`Error exporting SQL backup: ${error.message}`);
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
console.log(`Extracting the exported file ${this.gzFile}...`);
|
|
374
|
+
await (0, client_file_uploader_1.unzipFile)(this.gzFile, this.sqlFile);
|
|
375
|
+
await this.initSqlDumpType();
|
|
376
|
+
console.log(`${chalk_1.default.green('✓')} Extracted to ${this.sqlFile}`);
|
|
377
|
+
}
|
|
378
|
+
catch (err) {
|
|
379
|
+
const error = err;
|
|
380
|
+
await this.track('error', {
|
|
381
|
+
error_type: 'archive_extraction',
|
|
382
|
+
error_message: error.message,
|
|
383
|
+
stack: error.stack,
|
|
384
|
+
});
|
|
385
|
+
exit.withError(`Error extracting the SQL export: ${error.message}`);
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
console.log('Extracting site urls from the SQL file...');
|
|
389
|
+
this.siteUrls = await extractSiteUrls(this.sqlFile);
|
|
390
|
+
debug('Extracted site URLs: %j', this.siteUrls);
|
|
391
|
+
}
|
|
392
|
+
catch (err) {
|
|
393
|
+
const error = err;
|
|
394
|
+
await this.track('error', {
|
|
395
|
+
error_type: 'extract_site_urls',
|
|
396
|
+
error_message: error.message,
|
|
397
|
+
stack: error.stack,
|
|
398
|
+
});
|
|
399
|
+
exit.withError(`Error extracting site URLs: ${error.message}`);
|
|
400
|
+
}
|
|
401
|
+
try {
|
|
402
|
+
this.sdsSiteUrls = await this.getSiteUrlsFromSDS();
|
|
403
|
+
}
|
|
404
|
+
catch (err) {
|
|
405
|
+
const error = err;
|
|
406
|
+
await this.track('error', {
|
|
407
|
+
error_type: 'get_site_urls_from_sds',
|
|
408
|
+
error_message: error.message,
|
|
409
|
+
stack: error.stack,
|
|
410
|
+
});
|
|
411
|
+
exit.withError(`Error getting site URLs from SDS: ${error.message}`);
|
|
412
|
+
}
|
|
413
|
+
console.log('Generating search-replace configuration...');
|
|
414
|
+
this.generateSearchReplaceMap();
|
|
415
|
+
try {
|
|
416
|
+
console.log('Running the following search-replace operations on the SQL file:');
|
|
417
|
+
for (const [domain, landoDomain] of Object.entries(this.searchReplaceMap)) {
|
|
418
|
+
console.log(` ${domain} -> ${landoDomain}`);
|
|
419
|
+
}
|
|
420
|
+
await this.runSearchReplace();
|
|
421
|
+
console.log(`${chalk_1.default.green('✓')} Search-replace operation is complete`);
|
|
422
|
+
}
|
|
423
|
+
catch (err) {
|
|
424
|
+
const error = err;
|
|
425
|
+
await this.track('error', {
|
|
426
|
+
error_type: 'search_replace',
|
|
427
|
+
error_message: error.message,
|
|
428
|
+
stack: error.stack,
|
|
429
|
+
});
|
|
430
|
+
exit.withError(`Error replacing domains: ${error.message}`);
|
|
431
|
+
}
|
|
432
|
+
try {
|
|
433
|
+
console.log('Importing the SQL file...');
|
|
434
|
+
await this.runImport();
|
|
435
|
+
console.log(`${chalk_1.default.green('✓')} SQL file imported`);
|
|
436
|
+
}
|
|
437
|
+
catch (err) {
|
|
438
|
+
const error = err;
|
|
439
|
+
await this.track('error', {
|
|
440
|
+
error_type: 'import_sql_file',
|
|
441
|
+
error_message: error.message,
|
|
442
|
+
stack: error.stack,
|
|
443
|
+
});
|
|
444
|
+
exit.withError(`Error importing SQL file: ${error.message}`);
|
|
445
|
+
}
|
|
446
|
+
return true;
|
|
403
447
|
}
|
|
404
|
-
return true;
|
|
405
|
-
}
|
|
406
448
|
}
|
|
407
|
-
exports.DevEnvSyncSQLCommand = DevEnvSyncSQLCommand;
|
|
449
|
+
exports.DevEnvSyncSQLCommand = DevEnvSyncSQLCommand;
|