delete
command is not a function which should be granted lightly. If a version is actually
in use by an active process and is deleted, chaos will ensue. Rather than test for that, though, I'm going to
trust the user, except that if the version is actually the current version right now I'll refuse to
delete it.
One weird thing we have going on here is that instead of separate item and ver parameters, we have a single
itemver* parameter for each item/version to be deleted. First, this allows us to use checkboxes to denote
versions to be deleted, but second, our CGI handler won't record more than one parameter with a given name.
So each item/version has to have its own name. This parameter is simply itemver_<item>_<version>.
That should get us through.
See Loading the repository index from index.xml attr = query->attrs; while (attr) { if (!strncmp (attr->name, "itemver_", 8)) { strcpy (buf2, attr->name + 8); mark = strrchr (buf2, '_'); if (mark) { *mark = '\0'; mark++; See Actually deleting a version } } attr = attr->next; } |
printf ("Content-type: text/html\n"); printf ("Status: 302 Redirect\n"); printf ("Location: %s\n\n", xml_attrval (environment, "SCRIPT_NAME")); printf ("<html><head><title>Delete succeeded</title></head>\n"); printf ("<body><h2>Delete succeeded</h2></body></html>\n"); |
buf2
pointing at the item key, and mark
pointing at the version key. So we load the item and check that its current version isn't the one we're
trying to delete. If we're still cool on that, then we'll delete the version from the item file. If the
item now has no versions, we'll delete the item entry from the index and mark the index as dirty so it'll
get saved later.
Note that at this point we're not actually deleting any files. That will come later -- in version 2.0 of
the PDM, we'll want to split all the work of actually affecting the repository into a procdef repository
module (presumably shared with the core engine), and then leave the CGI wrapper around it. But that will
come later. Right now we just want to get things working at all. But when we can safely isolate things like
using 'rm' on Unix and 'del' on Windows, well, then I'll delete files.
object_revoke (current_user, "wftkpdm", attr->name + 8, NULL); user_save (current_user); holder = xml_loc (directory, sbuf); if (holder && strcmp (xml_attrval (holder, "curver"), mark) ) { sprintf (sbuf, "%s%s.xml", PROCESS_DEFINITION_REPOSITORY, buf2); file = fopen (sbuf, "r"); if (file) { item = xml_read (file); if (item) { sprintf (sbuf, "item.versions.version[%s]", mark); version = xml_loc (item, sbuf); if (version) { xml_delete (version); /* Here's where we'd delete the version file if we were deleting files. */ xml = xml_loc (item, "item.versions.version"); if (!xml) { /* Hey - no more versions. Delete the item. */ xml_delete (holder); index_dirty = 1; /* Again, here's where we'd delete the item file if we were that kind of person. */ } else { sprintf (sbuf, "%s%s.xml", PROCESS_DEFINITION_REPOSITORY, buf2); file = fopen (sbuf, "w"); if (file) { xml_write (file, item); fclose (file); } } } xml_free (item); } fclose (file); } } |
This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license. |