CleanCache maintenance script implemented

main
Inga 🏳‍🌈 15 years ago
parent fa112b55e7
commit 24cff59050
  1. 2
      Builder/IISMainHandler/build.txt
  2. 1
      Common/Common.csproj
  3. 2
      Common/Config.cs
  4. 34
      Common/TableManager.cs
  5. 2
      Common/dataobjects/Post.cs
  6. 20
      IISMainHandler/HandlersFactory.cs
  7. 2
      IISMainHandler/IISMainHandler.csproj
  8. 34
      IISMainHandler/handlers/request/maintenance/CleanCacheHandler.cs
  9. 31
      IISMainHandler/handlers/response/maintenance/CleanCacheHandler.cs
  10. 49
      templates/Full/maintenance/CleanCache.xslt
  11. 37
      templates/Full/result/maintenance/CacheCleaned.xslt

@ -106,6 +106,7 @@
<Compile Include="ISqlObjectTableSpec.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlObject.cs" />
<Compile Include="TableManager.cs" />
<Compile Include="UBBParser.cs" />
<Compile Include="BBCodes\I.cs" />
<Compile Include="UploadManager.cs" />

@ -27,6 +27,8 @@ namespace FLocal.Common {
public readonly TimeSpan ActivityThreshold;
public readonly string AdminUserName = "inga-lovinde";
protected Config(NameValueCollection data) : base(data) {
this.InitTime = DateTime.Now.ToLongTimeString();
this.mainConnection = new MySQLConnector.Connection(data["ConnectionString"], MySQLConnector.PostgresDBTraits.instance);

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Core;
namespace FLocal.Common {
public static class TableManager {
private static List<ISqlObjectTableSpec> _TABLES = new List<ISqlObjectTableSpec> {
dataobjects.Account.TableSpec.instance,
dataobjects.AccountIndicator.TableSpec.instance,
dataobjects.AccountSettings.TableSpec.instance,
dataobjects.Board.TableSpec.instance,
dataobjects.Category.TableSpec.instance,
dataobjects.PMConversation.TableSpec.instance,
dataobjects.PMMessage.TableSpec.instance,
dataobjects.Poll.TableSpec.instance,
dataobjects.Post.TableSpec.instance,
dataobjects.PostLayer.TableSpec.instance,
dataobjects.QuickLink.TableSpec.instance,
dataobjects.Revision.TableSpec.instance,
dataobjects.Session.TableSpec.instance,
dataobjects.Skin.TableSpec.instance,
dataobjects.Thread.TableSpec.instance,
dataobjects.Upload.TableSpec.instance,
dataobjects.User.TableSpec.instance,
dataobjects.UserGroup.TableSpec.instance,
};
public static Dictionary<string, ISqlObjectTableSpec> TABLES = (from table in _TABLES select new KeyValuePair<string, ISqlObjectTableSpec>(table.name, table)).ToDictionary();
}
}

@ -214,7 +214,7 @@ namespace FLocal.Common.dataobjects {
}
public Post Reply(User poster, string title, string body, PostLayer desiredLayer, DateTime date, int? forcedPostId) {
if(this.thread.isLocked && poster.name != "inga-lovinde") {
if(this.thread.isLocked && poster.name != Config.instance.AdminUserName) {
throw new FLocalException("thread locked");
}

@ -132,6 +132,16 @@ namespace FLocal.IISHandler {
default:
return new handlers.WrongUrlHandler();
}
case "maintenance":
if(context.requestParts.Length < 2) {
return new handlers.WrongUrlHandler();
}
switch(context.requestParts[1].ToLower()) {
case "cleancache":
return new handlers.response.maintenance.CleanCacheHandler();
default:
return new handlers.WrongUrlHandler();
}
case "poll":
if(context.requestParts.Length < 2) {
return new handlers.WrongUrlHandler();
@ -173,6 +183,16 @@ namespace FLocal.IISHandler {
return new handlers.request.CreatePollHandler();
case "vote":
return new handlers.request.VoteHandler();
case "maintenance":
if(context.requestParts.Length < 3) {
return new handlers.WrongUrlHandler();
}
switch(context.requestParts[2].ToLower()) {
case "cleancache":
return new handlers.request.maintenance.CleanCacheHandler();
default:
return new handlers.WrongUrlHandler();
}
default:
return new handlers.WrongUrlHandler();
}

@ -66,6 +66,7 @@
<Compile Include="handlers\request\EditHandler.cs" />
<Compile Include="handlers\request\LoginHandler.cs" />
<Compile Include="handlers\request\LogoutHandler.cs" />
<Compile Include="handlers\request\maintenance\CleanCacheHandler.cs" />
<Compile Include="handlers\request\MarkThreadAsReadHandler.cs" />
<Compile Include="handlers\request\MigrateAccountHandler.cs" />
<Compile Include="handlers\request\ReturnPostHandler.cs" />
@ -85,6 +86,7 @@
<Compile Include="handlers\response\LegacyPHPHandler.cs" />
<Compile Include="handlers\response\LegacyUploadHandler.cs" />
<Compile Include="handlers\response\LoginHandler.cs" />
<Compile Include="handlers\response\maintenance\CleanCacheHandler.cs" />
<Compile Include="handlers\response\MigrateAccountHandler.cs" />
<Compile Include="handlers\response\PMReplyHandler.cs" />
<Compile Include="handlers\response\PMReplyToPostHandler.cs" />

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using FLocal.Core;
using FLocal.Common;
namespace FLocal.IISHandler.handlers.request.maintenance {
class CleanCacheHandler : AbstractNewMessageHandler {
protected override string templateName {
get {
return "result/maintenance/CacheCleaned.xslt";
}
}
protected override XElement[] Do(WebContext context) {
if(context.account.user.name != Config.instance.AdminUserName) {
throw new FLocalException("access denied");
}
string table = context.httprequest.Form["table"].Trim();
int start = int.Parse(context.httprequest.Form["start"]);
int length = int.Parse(context.httprequest.Form["length"]);
ISqlObjectTableSpec tableSpec = TableManager.TABLES[table];
for(int i=0; i<length; i++) {
tableSpec.refreshSqlObject(start+i);
}
return new XElement[] {
};
}
}
}

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml.Linq;
using FLocal.Core;
using FLocal.Common;
using FLocal.Common.dataobjects;
namespace FLocal.IISHandler.handlers.response.maintenance {
class CleanCacheHandler : AbstractGetHandler {
override protected string templateName {
get {
return "maintenance/CleanCache.xslt";
}
}
override protected XElement[] getSpecificData(WebContext context) {
return new XElement[] {
new XElement(
"tables",
from kvp in TableManager.TABLES select new XElement("table", kvp.Key)
)
};
}
}
}

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="..\elems\Main.xslt"/>
<xsl:template name="specificTitle">Î÷èñòêà êýøà</xsl:template>
<xsl:template name="specific">
<table width="95%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="3" cellspacing="1" width="100%" class="tableborders">
<tr>
<td class="tdheader">
<xsl:text>Î÷èñòêà êýøà</xsl:text>
</td>
</tr>
<tr class="darktable">
<td>
<xsl:text>Âûáåðèòå òàáëèöó è íîìåðà</xsl:text>
</td>
</tr>
<tr>
<td class="lighttable">
<form method="post" action="/do/Maintenance/CleanCache/">
<xsl:text>Òàáëèöà</xsl:text><br />
<select name="table" class="formboxes">
<xsl:apply-templates select="tables/table"/>
</select>
<br/>
<xsl:text>Íà÷àòü ñ ID</xsl:text><br/>
<input type="text" name="start" class="formboxes" /><br/>
<xsl:text>Êîëè÷åñòâî</xsl:text><br/>
<input type="text" name="length" class="formboxes" value="1" /><br/>
<input type="submit" name="buttlogin" value="Î÷èñòèòü!" class="buttons" />
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="table">
<option>
<xsl:attribute name="value"><xsl:value-of select="current()"/></xsl:attribute>
<xsl:value-of select="current()"/>
</option>
</xsl:template>
</xsl:stylesheet>

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="..\..\elems\Main.xslt"/>
<xsl:template name="specificTitle">Êýø î÷èùåí</xsl:template>
<xsl:template name="specific">
<table width="95%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="3" cellspacing="1" width="100%" class="tableborders">
<tr>
<td class="tdheader">
<xsl:text>Î÷èñòêà êýøà</xsl:text>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="3" cellspacing="1" width="100%" class="tableborders">
<tr>
<td class="lighttable">
<p>Âûáðàííûå äàííûå îáíîâëåíû</p>
<br/>
<a>
<xsl:attribute name="href">/Maintenance/CleanCache/</xsl:attribute>
<xsl:text>Âåðíóòüñÿ ê î÷èñòêå êýøà</xsl:text>
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
Loading…
Cancel
Save