@automattic/vip 3.8.1 → 3.8.2

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.
@@ -30,10 +30,11 @@ const appQuery = `
30
30
  appQuery,
31
31
  envContext: true,
32
32
  requiredArgs: 0
33
- }).option('exportFileErrorsToJson', 'Export any file errors encountered to a JSON file instead of a plain text file', false).argv(process.argv, async (arg, {
33
+ }).option('exportFileErrorsToJson', 'Export any file errors encountered to a JSON file instead of a plain text file', false).option('saveErrorLog', 'Download file-error logs without prompting', 'prompt').argv(process.argv, async (arg, {
34
34
  app,
35
35
  env,
36
- exportFileErrorsToJson
36
+ exportFileErrorsToJson,
37
+ saveErrorLog
37
38
  }) => {
38
39
  const {
39
40
  id: envId,
@@ -56,6 +57,7 @@ Checking the Media import status for your environment...
56
57
  app,
57
58
  env,
58
59
  progressTracker,
59
- exportFileErrorsToJson
60
+ exportFileErrorsToJson,
61
+ saveErrorLog
60
62
  });
61
63
  });
@@ -79,18 +79,19 @@ ${_chalk.default.red.bold('If no `uploads/` directory is found, all files will b
79
79
 
80
80
  Are you sure you want to import the contents of the url?
81
81
  `
82
- }).command('status', 'Check the status of the latest Media Import').command('abort', 'Abort the Media Import running for your App').option('exportFileErrorsToJson', 'Export any file errors encountered to a JSON file instead of a plain text file', false).option('overwriteExistingFiles', 'Overwrite any existing files', false).option('importIntermediateImages', 'Import intermediate image files', false).examples(examples).argv(process.argv, async (args, opts) => {
82
+ }).command('status', 'Check the status of the latest Media Import').command('abort', 'Abort the Media Import running for your App').option('exportFileErrorsToJson', 'Export any file errors encountered to a JSON file instead of a plain text file', false).option('saveErrorLog', 'Download file-error logs without prompting').option('overwriteExistingFiles', 'Overwrite any existing files', false).option('importIntermediateImages', 'Import intermediate image files', false).examples(examples).argv(process.argv, async (args, opts) => {
83
83
  const {
84
84
  app,
85
85
  env,
86
86
  exportFileErrorsToJson,
87
+ saveErrorLog,
87
88
  overwriteExistingFiles,
88
89
  importIntermediateImages
89
90
  } = opts;
90
91
  const [url] = args;
91
92
  if (!isSupportedUrl(url)) {
92
93
  console.log(_chalk.default.red(`
93
- Error:
94
+ Error:
94
95
  Invalid URL provided: ${url}
95
96
  Please make sure that it is a publicly accessible web URL containing an archive of the media files to import`));
96
97
  return;
@@ -126,7 +127,8 @@ Importing Media into your App...
126
127
  app,
127
128
  env,
128
129
  progressTracker,
129
- exportFileErrorsToJson
130
+ exportFileErrorsToJson,
131
+ saveErrorLog
130
132
  });
131
133
  } catch (error) {
132
134
  if (error.graphQLErrors) {
@@ -296,6 +296,19 @@ _args.default.argv = async function (argv, cb) {
296
296
  }
297
297
  }
298
298
 
299
+ // Negotiate flag values
300
+ switch (_opts.module) {
301
+ case 'import-media':
302
+ if ([true, 'true', 'yes'].includes(options.saveErrorLog)) {
303
+ options.saveErrorLog = 'true';
304
+ } else if ([false, 'false', 'no'].includes(options.saveErrorLog)) {
305
+ options.saveErrorLog = 'false';
306
+ } else {
307
+ options.saveErrorLog = 'prompt';
308
+ }
309
+ break;
310
+ }
311
+
299
312
  // Prompt for confirmation if necessary
300
313
  if (_opts.requireConfirm && !options.force) {
301
314
  /** @type {Tuple[]} */
@@ -429,6 +442,10 @@ _args.default.argv = async function (argv, cb) {
429
442
  key: 'Export any file errors encountered to a JSON file instead of a plain text file.',
430
443
  value: options.exportFileErrorsToJson ? '✅ Yes' : `${_chalk.default.red('x')} No`
431
444
  });
445
+ info.push({
446
+ key: 'Download file-error logs?',
447
+ value: options.saveErrorLog
448
+ });
432
449
  break;
433
450
  default:
434
451
  }
@@ -80,7 +80,7 @@ async function getLandoConfig() {
80
80
  subdir: '.',
81
81
  namespace: '@lando'
82
82
  }],
83
- disablePlugins: ['@lando/argv', '@lando/mailhog', '@lando/phpmyadmin'],
83
+ disablePlugins: [],
84
84
  proxyName: 'vip-dev-env-proxy',
85
85
  userConfRoot: landoDir,
86
86
  home: fakeHomeDir,
@@ -59,7 +59,7 @@ class MediaImportProgressTracker {
59
59
  }
60
60
  const statusIcon = (0, _status.getGlyphForStatus)(this.status.status ?? '', this.runningSprite);
61
61
  let logs;
62
- if (this.status.filesProcessed && this.status.filesTotal) {
62
+ if (typeof this.status.filesProcessed === 'number' && this.status.filesTotal) {
63
63
  const progressPercentage = Math.floor(this.status.filesProcessed / this.status.filesTotal * 100);
64
64
  logs = `Imported Files: ${this.status.filesProcessed}/${this.status.filesTotal} - ${progressPercentage}% ${statusIcon}`;
65
65
  }
@@ -121,7 +121,8 @@ async function mediaImportCheckStatus({
121
121
  app,
122
122
  env,
123
123
  progressTracker,
124
- exportFileErrorsToJson
124
+ exportFileErrorsToJson,
125
+ saveErrorLog
125
126
  }) {
126
127
  // Stop printing so we can pass our callback
127
128
  progressTracker.stopPrinting();
@@ -241,11 +242,13 @@ Downloading errors details from ${fileErrorsUrl}
241
242
  }
242
243
  }
243
244
  async function promptFailureDetailsDownload(fileErrorsUrl) {
244
- const failureDetails = await (0, _enquirer.prompt)({
245
+ const failureDetails = 'prompt' === saveErrorLog ? await (0, _enquirer.prompt)({
245
246
  type: 'confirm',
246
247
  name: 'download',
247
248
  message: 'Download import errors report now? (Report will be downloadable for up to 7 days from the completion of the import)'
248
- });
249
+ }) : {
250
+ download: ['true', 'yes'].includes(saveErrorLog)
251
+ };
249
252
  if (!failureDetails.download) {
250
253
  progressTracker.suffix += `${_chalk.default.yellow(`⚠️ An error report file has been generated for this media import. Access it within the next 15 minutes by clicking on the URL below.`)}`;
251
254
  progressTracker.suffix += `\n${_chalk.default.yellow(`Or, generate a new URL by running the ${_chalk.default.bgYellow('vip import media status')} command.`)} `;
@@ -260,7 +263,7 @@ Downloading errors details from ${fileErrorsUrl}
260
263
  await exportFailureDetails(failureDetailsErrors);
261
264
  }
262
265
  function printFileErrorsReportLinkExpiredError(results) {
263
- if (results.filesTotal && results.filesProcessed && results.filesTotal !== results.filesProcessed) {
266
+ if (results.filesTotal && typeof results.filesProcessed === 'number' && results.filesTotal !== results.filesProcessed) {
264
267
  const errorsFound = results.filesTotal - results.filesProcessed;
265
268
  progressTracker.suffix += `${_chalk.default.yellow(`⚠️ ${errorsFound} error(s) were found. File import errors report link expired.`)}`;
266
269
  }
@@ -76,9 +76,6 @@ async function getStatus(api, appId, envId) {
76
76
  jobs,
77
77
  launched
78
78
  } = environment;
79
- if (!environment.isK8sResident && !jobs?.length) {
80
- return {};
81
- }
82
79
  const [importJob] = jobs ?? [];
83
80
  return {
84
81
  importStatus,
@@ -218,7 +215,7 @@ ${maybeExitPrompt}
218
215
  } = status;
219
216
  let jobStatus;
220
217
  let jobSteps = [];
221
- if (env.isK8sResident && !isMissingImportJobAndShouldReturnFast) {
218
+ if (!isMissingImportJobAndShouldReturnFast) {
222
219
  // in the future the API may provide this in k8s jobs so account for that.
223
220
  // Until then we need to create the importJob from the status object.
224
221
  if (!importJob) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.sqlDumpLineIsMultiSite = sqlDumpLineIsMultiSite;
5
- const SQL_CREATE_TABLE_IS_MULTISITE_REGEX = /^CREATE TABLE `?(wp_\d+_[a-z0-9_]*|wp_blogs)/i;
5
+ const SQL_CREATE_TABLE_IS_MULTISITE_REGEX = /^CREATE TABLE(?: IF NOT EXISTS)? `?(wp_\d+_[a-z0-9_]*|wp_blogs)/i;
6
6
  const SQL_CONTAINS_MULTISITE_WP_USERS_REGEX = /`spam` tinyint\(2\)|`deleted` tinyint\(2\)/i;
7
7
  function sqlDumpLineIsMultiSite(line) {
8
8
  // determine if we're on a CREATE TABLE statement line what has eg. wp_\d_options OR wp_blogs
@@ -40,7 +40,7 @@ const siteTypeValidations = exports.siteTypeValidations = {
40
40
  await track('import_sql_command_error', {
41
41
  error_type: 'subsite-import-without-subsite-sql-dump'
42
42
  });
43
- throw new Error('You have requested a subsite SQL import but have not provided a subsite compatiable SQL dump.');
43
+ throw new Error('You have requested a subsite SQL import but have not provided a subsite compatible SQL dump.');
44
44
  }
45
45
 
46
46
  // Get Primary Domain