File: flush.pike

package info (click to toggle)
roxen 1.2beta2-2
  • links: PTS
  • area: contrib
  • in suites: hamm
  • size: 16,948 kB
  • ctags: 8,589
  • sloc: ansic: 89,632; asm: 8,431; sh: 2,915; makefile: 1,787; cpp: 377
file content (139 lines) | stat: -rw-r--r-- 3,510 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * $Id: flush.pike,v 1.6 1998/03/11 19:18:52 neotron Exp $
 */

inherit "wizard";
constant name= "Cache//Flush caches...";

constant doc = ("Flush a cache or two");

mixed page_0(object id, object mc)
{
  return ("<font size=+1>Which caches do you want to flush?</font><p>"
	  "<var name=module_cache type=checkbox> The module cache<br>\n"
	  "<help><blockquote>"
	  "Force a flush of the module cache (used to describe "
	  "modules on the 'add module' page)"
	  "</blockquote></help>"
	  "<var name=user_cache type=checkbox> The user cache<br>\n"
	  "<help><blockquote>"
	  "Force a flush of the user and password cache in all "
	  "virtual servers."
	  "</blockquote></help>"
	  "<var default=1 name=memory_cache type=checkbox> The memory cache<br>\n"
	  "<help><blockquote>"
	  "Force a flush of the memory cache (the one described "
	  "under the Actions -> Cache -> Cache status)."
	  "</blockquote></help>"
	  "<var default=1 name=dir_cache type=checkbox> Directory caches<br>\n"
	  "<help><blockquote>"
	  "Force a flush of all directory module caches."
	  "</blockquote></help>"
	  "<var default=0 name=gtext_cache type=checkbox> Graphical text caches<br>\n"
	  "<help><blockquote>"
	  "Force a flush of the graphical text cache."
	  "</blockquote></help>");
}

#define CHECKED(x) (id->variables->x != "0")

mixed page_1(object id, object mc)
{
  string ret = "";
  if(CHECKED(user_cache))   ret += "The userdb cache<br>";
  if(CHECKED(memory_cache)) ret += "The memory cache<br>";    
  if(CHECKED(dir_cache))    ret += "The directory cache<br>";
  if(CHECKED(module_cache)) ret += "The module cache<br>";
  if(CHECKED(gtext_cache)) ret += "The graphical text cache<br>";
  if(!strlen(ret))
    ret = "No items selected!";

  return  "To flush the following caches press 'OK':\n<p>"+ ret;
}

string text_andify( array(string) info )
{
  int i=0;
  int l=sizeof(info);
  string ret;

  foreach( info, string item )
  {
    i++;
    if(i==1) ret = item;
    else
      if(i==l) ret += " and "+ item;
      else ret += ", "+ item;
  }

  return ret;
}

mixed wizard_done(object id, object mc)
{
  gc();

  array(string) info= ({ });
  
  /* Flush the userdb. */ 
  if(CHECKED(user_cache))
  {
    info += ({ "the userdb" });
    foreach(roxen->configurations, object c)
      if(c->modules["userdb"] && c->modules["userdb"]->master)
	c->modules["userdb"]->master->read_data();
  }
  
  /* Flush the memory cache. */ 
  if(CHECKED(memory_cache))
  {
    info += ({ "the memory cache" });
    function_object(cache_set)->cache = ([]);
  }

  /* Flush the gtext cache. */ 
  if(CHECKED(gtext_cache))
  {
    info += ({ "the graphical text cache" });
    foreach(roxen->configurations, object c)
    {
      if(c->modules["graphic_text"] && 
	 (c=c->modules["graphic_text"]->enabled))
      {
	catch{
	  foreach(get_dir(c->query("cache_dir")), string d)
	    rm(c->query("cache_dir")+d);
	};
      }
    }
  }

  /* Flush the dir cache. */ 
  if(CHECKED(dir_cache))
  {
    info += ({ "the directory cache" });
  foreach(roxen->configurations, object c)
    if(c->modules["directories"] && (c=c->modules["directories"]->enabled))
    {
      catch{
	c->_root->dest();
	c->_root = 0;
      };
    }
  }
  
  /* Flush the module cache. */ 
  if(CHECKED(module_cache))
  {
    info += ({ "the module cache" });
    roxen->allmodules=0;
    roxen->module_stat_cache=([]);
  }

  if(info)
    report_notice("Flushed "+ text_andify(info) +".");

  gc();
}

mixed handle(object id) { return wizard_for(id,0); }