Index: trunk/ippTools/src/magictool.c
===================================================================
--- trunk/ippTools/src/magictool.c	(revision 14537)
+++ trunk/ippTools/src/magictool.c	(revision 14666)
@@ -42,4 +42,6 @@
 static bool addskyfilemaskMode(pxConfig *config);
 
+static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state);
+
 # define MODECASE(caseName, func) \
     case caseName: \
@@ -94,5 +96,88 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
-    return 0;
+
+    // required options
+    bool status = false;
+    psString workdir = psMetadataLookupStr(&status, config->args, "-workdir");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -workdir");
+        return false;
+    }
+    if (!workdir) {
+        psError(PS_ERR_UNKNOWN, true, "-workdir is required");
+        return false;
+    }
+
+    psString label = psMetadataLookupStr(&status, config->args, "-label");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label");
+        return false;
+    }
+
+    psString dvodb = psMetadataLookupStr(&status, config->args, "-dvodb");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -dvodb");
+        return false;
+    }
+
+    psTime *registered = NULL;
+    {
+        psString registeredStr = psMetadataLookupStr(&status, config->args, "-registered");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -registered");
+            return false;
+        }
+        // pass through NULL as this is an optional field
+        if (registeredStr) {
+            registered = psTimeFromISO(registeredStr, PS_TIME_UTC);
+        } else {
+            registered = NULL;
+        }
+    }
+
+   magicRunRow *run = magicRunRowAlloc(
+            0,          // ID
+            "reg",      // state
+            workdir,
+            "dirty",    // workdir_state
+            label,
+            dvodb,
+            registered
+    );
+    psFree(registered);
+    if (!run) {
+        psError(PS_ERR_UNKNOWN, false, "failed to alloc magicRun object");
+        return true;
+    }
+    if (!magicRunInsertObject(config->dbh, run)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(run);
+        return true;
+    }
+
+    // get the assigned warp_id
+    psS64 magic_id = psDBLastInsertID(config->dbh);
+    run->magic_id = magic_id;
+
+    bool simple = false;
+    {
+        bool status = false;
+        simple = psMetadataLookupBool(&status, config->args, "-simple");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
+            psFree(run);
+            return false;
+        }
+    }
+
+    if (!magicRunPrintObject(stdout, run, !simple)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to print object");
+            psFree(run);
+            return false;
+    }
+
+    psFree(run);
+
+    return magic_id;
 }
 
@@ -101,4 +186,31 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
+
+    bool status = false;
+    psString magic_id = psMetadataLookupStr(&status, config->args, "-magic_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -magic_id");
+        return false;
+    }
+    if (!magic_id) {
+        psError(PS_ERR_UNKNOWN, true, "-magic_id is required");
+        return false;
+    }
+
+    psString state = psMetadataLookupStr(&status, config->args, "-state");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
+        return false;
+    }
+    if (!state) {
+        psError(PS_ERR_UNKNOWN, true, "-state is required");
+        return false;
+    }
+
+    if (state) {
+        // set detRun.state to state
+        return setmagicRunState(config, (psS64)atoll(magic_id), state);
+    }
+
     return true;
 }
@@ -1284,7 +1396,8 @@
     return true;
 }
-
-
-static bool setwarpRunState(pxConfig *config, psS64 warp_id, const char *state)
+#endif
+
+
+static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state)
 {
     PS_ASSERT_PTR_NON_NULL(state, false);
@@ -1298,19 +1411,20 @@
     ) {
         psError(PS_ERR_UNKNOWN, false,
-                "invalid warpRun state: %s", state);
-        return false;
-    }
-
-    char *query = "UPDATE warpRun SET state = '%s' WHERE warp_id = %" PRId64;
-    if (!p_psDBRunQuery(config->dbh, query, state, warp_id)) {
+                "invalid magicRun state: %s", state);
+        return false;
+    }
+
+    char *query = "UPDATE magicRun SET state = '%s' WHERE magic_id = %" PRId64;
+    if (!p_psDBRunQuery(config->dbh, query, state, magic_id)) {
         psError(PS_ERR_UNKNOWN, false,
-                "failed to change state for warp_id %" PRId64, warp_id);
-        return false;
-    }
-
-    return true;
-}
-
-
+                "failed to change state for magic_id %" PRId64, magic_id);
+        return false;
+    }
+
+    return true;
+}
+
+
+#if 0
 static bool isValidMode(pxConfig *config, const char *mode)
 {
