admin: New option to drop all solutions from the database
This commit is contained in:
parent
79afaa8fb2
commit
daae6f4f07
@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@ -136,6 +137,45 @@ func declareSyncRoutes(router *gin.RouterGroup) {
|
||||
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
|
||||
// Remove soluces from the database.
|
||||
apiSyncRoutes.POST("/drop_soluces", func(c *gin.Context) {
|
||||
exercices, err := fic.GetExercices()
|
||||
if err != nil {
|
||||
log.Println("Unable to GetExercices:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to retrieve exercices list."})
|
||||
return
|
||||
}
|
||||
|
||||
var errs error
|
||||
for _, e := range exercices {
|
||||
// Remove any published video
|
||||
if len(e.VideoURI) > 0 && strings.HasPrefix(e.VideoURI, "$FILES$") {
|
||||
vpath := path.Join(fic.FilesDir, strings.TrimPrefix(e.VideoURI, "$FILES$/"))
|
||||
err = os.Remove(vpath)
|
||||
if err != nil {
|
||||
errs = multierr.Append(errs, fmt.Errorf("unable to delete published video (%q): %w", e.VideoURI, err))
|
||||
}
|
||||
}
|
||||
|
||||
// Clean the database
|
||||
if len(e.VideoURI) > 0 || len(e.Resolution) > 0 {
|
||||
e.VideoURI = ""
|
||||
e.Resolution = ""
|
||||
|
||||
_, err = e.Update()
|
||||
if err != nil {
|
||||
errs = multierr.Append(errs, fmt.Errorf("unable to update exercice (%d: %s): %w", e.Id, e.Title, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errmsg": flatifySyncErrors(err)})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func declareSyncExercicesRoutes(router *gin.RouterGroup) {
|
||||
|
@ -859,6 +859,19 @@ angular.module("FICApp")
|
||||
});
|
||||
});
|
||||
};
|
||||
$scope.dropSoluces = function() {
|
||||
$scope.addToast('warning', 'Effacer les solutions', 'Ceci va retirer les textes de résolution de la base de données ainsi que les liens vers les vidéos.',
|
||||
function() {
|
||||
$scope.deepSyncInProgress = true;
|
||||
$http.post("api/sync/drop_soluces").then(function() {
|
||||
$scope.deepSyncInProgress = false;
|
||||
$scope.addToast('success', 'Effacement des solutions terminé.');
|
||||
}, function(response) {
|
||||
$scope.deepSyncInProgress = false;
|
||||
$scope.addToast('danger', 'Effacement des solutions terminé avec des erreurs.', response.data.errmsg);
|
||||
});
|
||||
});
|
||||
};
|
||||
})
|
||||
|
||||
.controller("PKIController", function($scope, $rootScope, Certificate, CACertificate, Team, $location, $http) {
|
||||
|
@ -54,6 +54,7 @@
|
||||
</div>
|
||||
<button type="button" class="btn btn-secondary" ng-click="speedyDeepSync()" ng-disabled="deepSyncInProgress"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Synchronisation sans fichiers</button>
|
||||
<button type="button" class="btn btn-info" ng-if="settings.wip" ng-click="syncVideos()" ng-disabled="deepSyncInProgress"><span class="glyphicon glyphicon-facetime-video" aria-hidden="true"></span> Mettre à disposition les vidéos</button>
|
||||
<button type="button" class="btn btn-danger" ng-click="dropSoluces()" ng-disabled="deepSyncInProgress" title="Par solutions, on entend les résolutions écrites dans la base de données, les liens vers les fichiers vidéos">Effacer les solutions</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user