@@ -286,9 +286,8 @@ function processPlugin( repo, fn ) {
286
286
return fn ( null ) ;
287
287
}
288
288
289
- var allErrors = [ ] ,
290
- // TODO: track our actions so we can process metadata in done()
291
- plugins = { } ,
289
+ // TODO: track our actions so we can process metadata in done()
290
+ var plugins = { } ,
292
291
waiting = versions . length ;
293
292
294
293
function progress ( ) {
@@ -299,6 +298,7 @@ function processPlugin( repo, fn ) {
299
298
}
300
299
301
300
function done ( ) {
301
+ // TODO: track invalid versions (user error, not system error)
302
302
// TODO: update versionless post to have latest version
303
303
// TODO: update metadata in WP
304
304
// - don't list pre-release versions that are older than latest stable
@@ -314,43 +314,78 @@ function processPlugin( repo, fn ) {
314
314
return progress ( ) ;
315
315
}
316
316
317
- var package = data . package ;
318
-
319
317
if ( data . errors . length ) {
320
- allErrors . concat ( data . errors ) ;
318
+ // TODO: report errors to user
321
319
return progress ( ) ;
322
320
}
323
321
324
- // find out who owns this plugin
325
- // if there is no owner, then set the user as the owner
326
- pluginsDb . getOrSetOwner ( package . name , repoDetails . userName , function ( error , owner ) {
322
+ wordpress . getVersions ( data . package . name , function ( error , versions ) {
327
323
if ( error ) {
328
324
// TODO: log failure for retry
329
325
return progress ( ) ;
330
326
}
331
327
332
- // the plugin is owned by someone else
333
- if ( owner !== repoDetails . userName ) {
328
+ // this version has already been processed
329
+ // TODO: when should we start passing around the clean version?
330
+ if ( versions . indexOf ( semver . clean ( version ) ) !== - 1 ) {
334
331
return progress ( ) ;
335
332
}
336
333
337
- // TODO: track action in sqlite
338
-
339
- // add additional metadata and generate the plugin page
340
- package . _downloadUrl = repoDetails . downloadUrl ( version ) ;
341
- _generatePage ( package , function ( error , data ) {
334
+ _addPluginVersion ( version , data . package , function ( error ) {
342
335
if ( error ) {
343
- // TODO: log failure for retry
344
336
return progress ( ) ;
345
337
}
346
338
347
- wordpress . addVersionedPlugin ( data , function ( error ) {
348
- if ( error ) {
349
- // TODO: log failure for retry
350
- }
351
- console . log ( "Added " + data . pluginName + " " + data . version ) ;
352
- progress ( ) ;
353
- } ) ;
339
+ var name = data . package . name ;
340
+ if ( ! plugins [ name ] ) {
341
+ plugins [ name ] = [ ] ;
342
+ }
343
+ plugins [ name ] . push ( semver . clean ( version ) ) ;
344
+ progress ( ) ;
345
+ } ) ;
346
+ } ) ;
347
+ } ) ;
348
+ } ) ;
349
+ }
350
+
351
+ function _addPluginVersion ( version , package , fn ) {
352
+ // find out who owns this plugin
353
+ // if there is no owner, then set the user as the owner
354
+ pluginsDb . getOrSetOwner ( package . name , repoDetails . userName , function ( error , owner ) {
355
+ if ( error ) {
356
+ // TODO: log failure for retry
357
+ return fn ( error ) ;
358
+ }
359
+
360
+ // the plugin is owned by someone else
361
+ if ( owner !== repoDetails . userName ) {
362
+ // TODO: report error to user
363
+ return fn ( createError ( "Plugin owned by someone else." , "NOT_OWNER" , {
364
+ owner : owner
365
+ } ) ) ;
366
+ }
367
+
368
+ pluginsDb . addVersion ( repoDetails , package , function ( error ) {
369
+ if ( error ) {
370
+ // TODO: log failure for retry
371
+ return fn ( error ) ;
372
+ }
373
+
374
+ // add additional metadata and generate the plugin page
375
+ package . _downloadUrl = repoDetails . downloadUrl ( version ) ;
376
+ _generatePage ( package , function ( error , data ) {
377
+ if ( error ) {
378
+ // TODO: log failure for retry
379
+ return fn ( error ) ;
380
+ }
381
+
382
+ wordpress . addVersionedPlugin ( data , function ( error ) {
383
+ if ( error ) {
384
+ // TODO: log failure for retry
385
+ return fn ( error ) ;
386
+ }
387
+ console . log ( "Added " + data . pluginName + " " + data . version ) ;
388
+ fn ( ) ;
354
389
} ) ;
355
390
} ) ;
356
391
} ) ;
0 commit comments