@automattic/vip 2.27.0-dev6 → 2.27.0-dev7
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.
|
Binary file
|
|
@@ -20,6 +20,7 @@ var _devEnvironmentLando = require("../lib/dev-environment/dev-environment-lando
|
|
|
20
20
|
var _userError = _interopRequireDefault(require("../lib/user-error"));
|
|
21
21
|
var _devEnvSyncSql = require("../commands/dev-env-sync-sql");
|
|
22
22
|
var _devEnvironment = require("../lib/constants/dev-environment");
|
|
23
|
+
var _tracker = require("../lib/tracker");
|
|
23
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
25
|
const examples = [{
|
|
25
26
|
usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} sync sql @my-test.develop --slug=my_site`,
|
|
@@ -50,11 +51,21 @@ const appQuery = `
|
|
|
50
51
|
env,
|
|
51
52
|
slug
|
|
52
53
|
}) => {
|
|
54
|
+
const trackerFn = (0, _tracker.makeCommandTracker)('dev_env_sync_sql', {
|
|
55
|
+
app: app.id,
|
|
56
|
+
env: env.uniqueLabel,
|
|
57
|
+
slug
|
|
58
|
+
});
|
|
59
|
+
await trackerFn('execute');
|
|
53
60
|
const lando = await (0, _devEnvironmentLando.bootstrapLando)();
|
|
54
61
|
const envPath = (0, _devEnvironmentCore.getEnvironmentPath)(slug);
|
|
55
62
|
if (!(await (0, _devEnvironmentLando.isEnvUp)(lando, envPath))) {
|
|
63
|
+
await trackerFn('env_not_running_error', {
|
|
64
|
+
errorMessage: 'Environment was not running'
|
|
65
|
+
});
|
|
56
66
|
throw new _userError.default('Environment needs to be started first');
|
|
57
67
|
}
|
|
58
|
-
const cmd = new _devEnvSyncSql.DevEnvSyncSQLCommand(app, env, slug);
|
|
68
|
+
const cmd = new _devEnvSyncSql.DevEnvSyncSQLCommand(app, env, slug, trackerFn);
|
|
59
69
|
await cmd.run();
|
|
70
|
+
await trackerFn('success');
|
|
60
71
|
});
|
|
@@ -73,14 +73,16 @@ class DevEnvSyncSQLCommand {
|
|
|
73
73
|
/**
|
|
74
74
|
* Creates a new instance of the command
|
|
75
75
|
*
|
|
76
|
-
* @param {string}
|
|
77
|
-
* @param {string}
|
|
78
|
-
* @param {string}
|
|
76
|
+
* @param {string} app The app object
|
|
77
|
+
* @param {string} env The environment object
|
|
78
|
+
* @param {string} slug The site slug
|
|
79
|
+
* @param {Function} trackerFn Function to call for tracking
|
|
79
80
|
*/
|
|
80
|
-
constructor(app, env, slug) {
|
|
81
|
+
constructor(app, env, slug, trackerFn = () => {}) {
|
|
81
82
|
this.app = app;
|
|
82
83
|
this.env = env;
|
|
83
84
|
this.slug = slug;
|
|
85
|
+
this.track = trackerFn;
|
|
84
86
|
this.tmpDir = (0, _utils.makeTempDir)();
|
|
85
87
|
}
|
|
86
88
|
get landoDomain() {
|
|
@@ -100,7 +102,7 @@ class DevEnvSyncSQLCommand {
|
|
|
100
102
|
* @return {Promise<void>} Promise that resolves when the export is complete
|
|
101
103
|
*/
|
|
102
104
|
async generateExport() {
|
|
103
|
-
const exportCommand = new _exportSql.ExportSQLCommand(this.app, this.env, this.gzFile);
|
|
105
|
+
const exportCommand = new _exportSql.ExportSQLCommand(this.app, this.env, this.gzFile, this.track);
|
|
104
106
|
await exportCommand.run();
|
|
105
107
|
}
|
|
106
108
|
|
|
@@ -158,6 +160,9 @@ class DevEnvSyncSQLCommand {
|
|
|
158
160
|
await (0, _clientFileUploader.unzipFile)(this.gzFile, this.sqlFile);
|
|
159
161
|
console.log(`${_chalk.default.green('✓')} Extracted to ${this.sqlFile}`);
|
|
160
162
|
} catch (err) {
|
|
163
|
+
await this.track('archive_extraction_error', {
|
|
164
|
+
errorMessage: err === null || err === void 0 ? void 0 : err.message
|
|
165
|
+
});
|
|
161
166
|
exit.withError(`Error extracting the SQL export: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
162
167
|
}
|
|
163
168
|
try {
|
|
@@ -174,6 +179,9 @@ class DevEnvSyncSQLCommand {
|
|
|
174
179
|
await this.runSearchReplace();
|
|
175
180
|
console.log(`${_chalk.default.green('✓')} Search-replace operation is complete`);
|
|
176
181
|
} catch (err) {
|
|
182
|
+
await this.track('search_replace_error', {
|
|
183
|
+
errorMessage: err === null || err === void 0 ? void 0 : err.message
|
|
184
|
+
});
|
|
177
185
|
exit.withError(`Error replacing domains: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
178
186
|
}
|
|
179
187
|
try {
|
|
@@ -181,6 +189,9 @@ class DevEnvSyncSQLCommand {
|
|
|
181
189
|
await this.runImport();
|
|
182
190
|
console.log(`${_chalk.default.green('✓')} SQL file imported`);
|
|
183
191
|
} catch (err) {
|
|
192
|
+
await this.track('import_error', {
|
|
193
|
+
errorMessage: err === null || err === void 0 ? void 0 : err.message
|
|
194
|
+
});
|
|
184
195
|
exit.withError(`Error importing SQL file: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
185
196
|
}
|
|
186
197
|
}
|
|
@@ -190,15 +190,15 @@ class ExportSQLCommand {
|
|
|
190
190
|
DOWNLOAD_LINK: 'downloadLink',
|
|
191
191
|
DOWNLOAD: 'download'
|
|
192
192
|
};
|
|
193
|
-
|
|
194
193
|
/**
|
|
195
194
|
* Creates an instance of SQLExportCommand
|
|
196
195
|
*
|
|
197
|
-
* @param {any}
|
|
198
|
-
* @param {any}
|
|
199
|
-
* @param {string}
|
|
196
|
+
* @param {any} app The application object
|
|
197
|
+
* @param {any} env The environment object
|
|
198
|
+
* @param {string} outputFile The output file path
|
|
199
|
+
* @param {Function} trackerFn The progress tracker function
|
|
200
200
|
*/
|
|
201
|
-
constructor(app, env, outputFile) {
|
|
201
|
+
constructor(app, env, outputFile, trackerFn = () => {}) {
|
|
202
202
|
this.app = app;
|
|
203
203
|
this.env = env;
|
|
204
204
|
this.outputFile = outputFile;
|
|
@@ -215,6 +215,7 @@ class ExportSQLCommand {
|
|
|
215
215
|
id: this.steps.DOWNLOAD,
|
|
216
216
|
name: 'Downloading file'
|
|
217
217
|
}]);
|
|
218
|
+
this.track = trackerFn;
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
/**
|
|
@@ -314,6 +315,9 @@ class ExportSQLCommand {
|
|
|
314
315
|
latestBackup
|
|
315
316
|
} = await fetchLatestBackupAndJobStatus(this.app.id, this.env.id);
|
|
316
317
|
if (!latestBackup) {
|
|
318
|
+
await this.track('no_backup_found_error', {
|
|
319
|
+
errorMessage: 'No backup found for the site'
|
|
320
|
+
});
|
|
317
321
|
exit.withError(`No backup found for site ${this.app.name}`);
|
|
318
322
|
} else {
|
|
319
323
|
console.log(`${(0, _format.getGlyphForStatus)('success')} Latest backup found with timestamp ${latestBackup.createdAt}`);
|
|
@@ -327,6 +331,9 @@ class ExportSQLCommand {
|
|
|
327
331
|
} catch (err) {
|
|
328
332
|
// Todo: match error code instead of message substring
|
|
329
333
|
if (err !== null && err !== void 0 && err.message.includes('Backup Copy already in progress')) {
|
|
334
|
+
await this.track('export_job_already_running_error', {
|
|
335
|
+
errorMessage: err === null || err === void 0 ? void 0 : err.message
|
|
336
|
+
});
|
|
330
337
|
exit.withError('There is an export job already running for this site: ' + `https://dashboard.wpvip.com/apps/${this.app.id}/${this.env.uniqueLabel}/data/database/backups\n` + 'Currently, we allow only one export job per site. Please try again later.');
|
|
331
338
|
}
|
|
332
339
|
exit.withError(`Error creating export job: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
@@ -350,6 +357,9 @@ class ExportSQLCommand {
|
|
|
350
357
|
} catch (err) {
|
|
351
358
|
this.progressTracker.stepFailed(this.steps.DOWNLOAD);
|
|
352
359
|
this.stopProgressTracker();
|
|
360
|
+
await this.track('download_failed_error', {
|
|
361
|
+
errorMessage: err === null || err === void 0 ? void 0 : err.message
|
|
362
|
+
});
|
|
353
363
|
exit.withError(`Error downloading exported file: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
354
364
|
}
|
|
355
365
|
}
|
package/dist/lib/tracker.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.aliasUser = aliasUser;
|
|
7
|
+
exports.makeCommandTracker = makeCommandTracker;
|
|
7
8
|
exports.trackEvent = trackEvent;
|
|
8
9
|
exports.trackEventWithEnv = trackEventWithEnv;
|
|
9
10
|
var _index = _interopRequireDefault(require("./analytics/index"));
|
|
@@ -77,4 +78,13 @@ async function trackEventWithEnv(appId, envId, eventName, eventProps = {}) {
|
|
|
77
78
|
app_id: appId,
|
|
78
79
|
env_id: envId
|
|
79
80
|
});
|
|
81
|
+
}
|
|
82
|
+
function makeCommandTracker(command, trackingInfo = {}) {
|
|
83
|
+
const trackerFn = async (type, data = {}) => {
|
|
84
|
+
await trackEvent(`${command}_command_${type}`, {
|
|
85
|
+
...trackingInfo,
|
|
86
|
+
...data
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
return trackerFn;
|
|
80
90
|
}
|
package/package.json
CHANGED
|
Binary file
|