All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.yawp.tools.datastore.DeleteAllTool Maven / Gradle / Ivy

There is a newer version: 2.08alpha
Show newest version
package io.yawp.tools.datastore;

import io.yawp.tools.Tool;

public class DeleteAllTool extends Tool {

    public static final String CONFIRM_PARAM = "confirm";

    @Override
    public void execute() {
        if (!confirm()) {
            pw.println("use: datastore/delete-all?confirm=" + System.currentTimeMillis());
            return;
        }

        deleteAll();
    }

    private void deleteAll() {
        yawp.driver().helpers().deleteAll();
        pw.println("ok");
    }

    private boolean confirm() {
        if (!yawp.driver().environment().isProduction()) {
            return true;
        }

        if (!params.containsKey(CONFIRM_PARAM)) {
            return false;
        }

        String confirmTime = params.get(CONFIRM_PARAM);
        Long confirm = Long.parseLong(confirmTime);
        long time = System.currentTimeMillis();
        if (confirm > time || confirm < time - 60000) {
            return false;
        }

        return true;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy