--- old/acl.module	2008-03-13 03:18:00.000000000 +0530
+++ new/acl.module	2008-03-15 10:52:37.406250000 +0530
@@ -10,6 +10,10 @@
  * ACLs can easily co-exist with the existing node_access system.
  */
 
+if (module_exists('workflow_ng')) {
+  include_once(drupal_get_path('module', 'acl') .'/acl_workflow_ng.inc');
+}
+
 /**
  * Create a new ACL.
  */
@@ -21,10 +25,21 @@ function acl_create_new_acl($module, $na
 
 /**
  * Delete an existing ACL.
+ *   If TRUE it will write the reduced node grants to the database.
+ *   BEWARE: This may load a large number of nodes, possibly more than
+ *   your web server can take without exhausting memory or timing out;
+ *   this would leave the database in an inconsistent state!
  */
-function acl_delete_acl($acl_id) {
+function acl_delete_acl($acl_id, $write_grants = FALSE) {
   db_query("DELETE FROM {acl} WHERE acl_id = %d", $acl_id);
   db_query("DELETE FROM {acl_user} WHERE acl_id = %d", $acl_id);
+  if ($write_grants) {
+    $result = db_query("SELECT * FROM {acl_node} WHERE acl_id = %d", $acl_id);
+    while ($data = db_fetch_object($result)) {
+      $node = node_load($data->nid);
+      node_access_acquire_grants($node);
+    }
+  }
   db_query("DELETE FROM {acl_node} WHERE acl_id = %d", $acl_id);
 }
 
@@ -178,13 +193,19 @@ function acl_node_add_acl($nid, $acl_id,
 
 /**
  * Remove an ACL completely from a node.
+ * 
+ * @return 
+ *   TRUE if the ACL was removed. 
  */
 function acl_node_remove_acl($nid, $acl_id) {
   db_query("DELETE FROM {acl_node} WHERE acl_id = %d AND nid = %d", $acl_id, $nid);
+  return (boolean)db_affected_rows(); 
 }
 
 /**
  * Clear all of a module's ACL's from a node.
+ * @return 
+ *  TRUE if there were any ACL's deleted from the node. 
  */
 function acl_node_clear_acls($nid, $module) {
   $result = db_query("SELECT acl_id FROM {acl} WHERE module = '%s'", $module);
@@ -194,14 +215,23 @@ function acl_node_clear_acls($nid, $modu
   if ($acls) {
     db_query("DELETE FROM {acl_node} WHERE nid = %d AND acl_id in (%s)", $nid,
       implode(',', $acls));
+    return (boolean)db_affected_rows();   
   }
 }
 
 /**
  * Gets the id of an acl
- */
-function acl_get_id_by_name($module, $name) {
-  return db_result(db_query("SELECT acl_id FROM {acl} WHERE module = '%s' AND name = '%s'", $module, $name));
+ * @param $auto_create
+ *    If TRUE it will create a new acl if an acl not found
+ * @return 
+ *   The acl
+ */
+function acl_get_id_by_name($module, $name, $auto_create = FALSE) {
+  $acl_id = db_result(db_query("SELECT acl_id FROM {acl} WHERE module = '%s' AND name = '%s'", $module, $name));
+  if ($auto_create && !$acl_id) {
+    $acl_id = acl_create_new_acl('acl', $name);
+  }
+  return $acl_id;
 }
 
 /**
