Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

#604 Purge RE: Statements For Different Languages From Database #693

Merged
merged 5 commits into from

2 participants

@xillibit
Owner

No description provided.

...nistrator/components/com_kunena/controllers/tools.php
((6 lines not shown))
+ $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
+ $this->setRedirect(KunenaRoute::_($this->baseurl, false));
+ return;
+ }
+
+ $db = JFactory::getDBO();
+ $query = "SELECT id, subject FROM #__kunena_messages WHERE parent != 0";
+ $db->setQuery ( $query );
+ $subjects = $db->loadObjectList ();
+ KunenaError::checkDatabaseError();
+
+ if ( is_array($subjects) ) {
+ $total_count = 0;
+ foreach($subjects as $subject) {
+ $subject_origin = $subject->subject;
+ $subject->subject = preg_replace('/Re:/','',$subject->subject, -1, $count);
@mahagr Owner
mahagr added a note

This cannot work as in Finnish we have Vs: and in other languages the string could be anything else. There can also be multiple Re: Vs: Re: in the reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...nistrator/components/com_kunena/controllers/tools.php
@@ -228,6 +228,40 @@ public function fixlegacy() {
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
}
+ public function purgeReStatements() {
+ if (!JRequest::checkToken()) {
+ $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
+ $this->setRedirect(KunenaRoute::_($this->baseurl, false));
+ return;
+ }
+
+ $db = JFactory::getDBO();
+ $query = "SELECT id, subject FROM #__kunena_messages WHERE parent != 0";
+ $db->setQuery ( $query );
@mahagr Owner
mahagr added a note

Without limit this query will fail on almost every forum. For me it returns 200k messages and runs out of memory.

We need to break this into smaller parts. Easiest way is query something like this:

SELECT id, subject FROM #__kunena_messages WHERE parent != 0 AND subject LIKE 'Re:%' LIMIT 1000

and do it a few times. I think we can even make a query that updates subject in MySQL without needing any PHP...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mahagr
Owner

UPDATE #_kunena_messages SET subject=TRIM(TRIM(LEADING 'Vs:' FROM subject)) WHERE subject LIKE 'Vs:%'

Cleans up the whole database from Finnish version of "Re:" and takes only seconds to run for 200k messages.

...onents/com_kunena/language/en-GB/en-GB.com_kunena.ini
@@ -26,4 +26,993 @@ COM_KUNENA_INTEGRATION_TYPE_JOMSOCIAL="JomSocial"
COM_KUNENA_INTEGRATION_TYPE_JOOMLA_GROUP="User Groups"
COM_KUNENA_INTEGRATION_TYPE_JOOMLA_LEVEL="Access Level"
+; End of automatically generated strings for COM_KUNENA_INTEGRATION_*
@mahagr Owner
mahagr added a note

Can you revert this change? The file was changed and you changed it back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mahagr mahagr merged commit 1fd5baa into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
31 administrator/components/com_kunena/controllers/tools.php
@@ -228,6 +228,37 @@ public function fixlegacy() {
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
}
+ public function purgeReStatements() {
+ if (!JRequest::checkToken()) {
+ $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
+ $this->setRedirect(KunenaRoute::_($this->baseurl, false));
+ return;
+ }
+
+ $re_string = JRequest::getString('re_string', null);
+
+ if ( $re_string != null ) {
+ $db = JFactory::getDBO();
+ $query = "UPDATE #__kunena_messages SET subject=TRIM(TRIM(LEADING '{$re_string}' FROM subject)) WHERE subject LIKE '{$re_string}%'";
+ $db->setQuery ( $query );
+ $db->Query ();
+ KunenaError::checkDatabaseError();
+
+ $count = $db->getAffectedRows ();
+
+ if ( $count > 0 ) {
+ $this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_MENU_RE_PURGED', $count, $re_string ) );
+ $this->setRedirect(KunenaRoute::_($this->baseurl, false));
+ } else {
+ $this->app->enqueueMessage ( JText::sprintf('COM_KUNENA_MENU_RE_PURGE_FAILED', $re_string) );
+ $this->setRedirect(KunenaRoute::_($this->baseurl, false));
+ }
+ } else {
+ $this->app->enqueueMessage ( JText::_('COM_KUNENA_MENU_RE_PURGE_FORGOT_STATEMENT') );
+ $this->setRedirect(KunenaRoute::_($this->baseurl, false));
+ }
+ }
+
protected function checkTimeout($stop = false) {
static $start = null;
if ($stop) $start = 0;
View
3  administrator/components/com_kunena/language/en-GB/en-GB.com_kunena.controllers.ini
@@ -90,6 +90,9 @@ COM_KUNENA_RECOUNTFORUMS_DONE="All category statistics have been recounted."
COM_KUNENA_SYNC_USERS_DO_ADD="User profiles added:"
COM_KUNENA_SYNC_USERS_DO_DEL="User profiles removed:"
COM_KUNENA_SYNC_USERS_DO_RENAME="Messages updated:"
+COM_KUNENA_MENU_RE_PURGED="%s subjects with %s statements has been purged from database"
+COM_KUNENA_MENU_RE_PURGE_FAILED="The statement %s hasn't been found in messages subject"
+COM_KUNENA_MENU_RE_PURGE_FORGOT_STATEMENT="You have forgot to enter a statement"
; JROOT/administrator/components/com_kunena/controllers/topicicons.php
View
2  administrator/components/com_kunena/language/en-GB/en-GB.com_kunena.ini
@@ -26,4 +26,4 @@ COM_KUNENA_INTEGRATION_TYPE_JOMSOCIAL="JomSocial"
COM_KUNENA_INTEGRATION_TYPE_JOOMLA_GROUP="User Groups"
COM_KUNENA_INTEGRATION_TYPE_JOOMLA_LEVEL="Access Level"
-; End of automatically generated strings for COM_KUNENA_INTEGRATION_TYPE_*
+; End of automatically generated strings for COM_KUNENA_INTEGRATION_*
View
1  administrator/components/com_kunena/media/css/admin.css
@@ -119,6 +119,7 @@ div.kadmin-functitle.icon-stats { background: url(../icons/large/stats.png) 5px
div.kadmin-functitle.icon-systemreport { background: url(../icons/large/report.png) 5px 5px no-repeat; }
div.kadmin-functitle.icon-support { background: url(../icons/large/support.png) 5px 5px no-repeat; }
div.kadmin-functitle.icon-editcss { background: url(../icons/large/css.png) 5px 5px no-repeat; }
+div.kadmin-functitle.icon-purgerestatements { background: url(../icons/large/purgerestatements.png) 5px 5px no-repeat; }
div.kadmin-functitle.no-icon { text-indent: 5px !important; }
View
1  administrator/components/com_kunena/media/css/admin.rtl.css
@@ -61,6 +61,7 @@ div.kadmin-functitle.icon-stats { background-position: right center;margin-right
div.kadmin-functitle.icon-systemreport { background-position: right center;margin-right:5px;margin-top:5px; }
div.kadmin-functitle.icon-support { background-position: right center;margin-right:5px;margin-top:5px; }
div.kadmin-functitle.icon-template { background-position: right center;margin-right:5px;margin-top:5px; }
+div.kadmin-functitle.icon-purgerestatements { background-position: right center;margin-right:5px;margin-top:5px; }
.left { text-align:right; }
.right { text-align:left; }
View
BIN  administrator/components/com_kunena/media/icons/large/purgerestatements.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3  administrator/components/com_kunena/views/tools/tmpl/default.php
@@ -36,6 +36,9 @@
<div class="icon-container">
<div class="icon"> <a href="<?php echo KunenaRoute::_('administrator/index.php?option=com_kunena&view=tools&layout=menu') ?>" title="<?php echo JText::_('COM_KUNENA_A_MENU_MANAGER');?>"> <img src="<?php echo JURI::base(true); ?>/components/com_kunena/media/icons/large/menu.png" align="middle" border="0" alt="" /> <span> <?php echo JText::_('COM_KUNENA_A_MENU_MANAGER'); ?> </span></a> </div>
</div>
+ <div class="icon-container">
+ <div class="icon"> <a href="<?php echo KunenaRoute::_('administrator/index.php?option=com_kunena&view=tools&layout=purgerestatements') ?>" title="<?php echo JText::_('COM_KUNENA_A_PURGE_RE_STATEMENTS');?>"> <img src="<?php echo JURI::base(true); ?>/components/com_kunena/media/icons/large/purgerestatements.png" align="middle" border="0" alt="" /> <span> <?php echo JText::_('COM_KUNENA_A_PURGE_RE_STATEMENTS'); ?> </span></a> </div>
+ </div>
<?php if (KunenaForum::isDev()) { ?>
<div class="icon-container">
<div class="icon"> <a href="<?php echo KunenaRoute::_('administrator/index.php?option=com_kunena&view=install&task=prepare&start=1&'.JUtility::getToken().'=1') ?>" title="<?php echo JText::_('COM_KUNENA_GIT_INSTALL');?>"> <img src="<?php echo JURI::base(true); ?>/components/com_kunena/media/icons/large/install.png" align="middle" border="0" alt="" /> <span> <?php echo JText::_('COM_KUNENA_GIT_INSTALL'); ?> </span></a> </div>
View
40 administrator/components/com_kunena/views/tools/tmpl/purgerestatements.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Kunena Component
+ * @package Kunena.Administrator.Template
+ * @subpackage SyncUsers
+ *
+ * @copyright (C) 2008 - 2011 Kunena Team. All rights reserved.
+ * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
+ * @link http://www.kunena.org
+ **/
+defined ( '_JEXEC' ) or die ();
+
+$document = JFactory::getDocument();
+$document->addStyleSheet ( JURI::base(true).'/components/com_kunena/media/css/admin.css' );
+if (JFactory::getLanguage()->isRTL()) $document->addStyleSheet ( JURI::base().'components/com_kunena/media/css/admin.rtl.css' );
+?>
+<div id="kadmin">
+ <div class="kadmin-left"><?php include KPATH_ADMIN.'/views/common/tmpl/menu.php'; ?></div>
+ <div class="kadmin-right">
+ <div class="kadmin-functitle icon-purgerestatements"><?php echo JText::_('COM_KUNENA_A_PURGE_RE_STATEMENTS'); ?></div>
+ <form action="<?php echo KunenaRoute::_('administrator/index.php?option=com_kunena&view=tools') ?>" method="post" id="adminForm" name="adminForm">
+ <input type="hidden" name="task" value="purgeReStatements" />
+ <?php echo JHTML::_( 'form.token' ); ?>
+
+ <fieldset>
+ <legend><?php echo JText::_('COM_KUNENA_A_PURGE_RE_STATEMENTS'); ?></legend>
+ <table class="kadmin-adminform">
+ <tr>
+ <td><?php echo JText::_('COM_KUNENA_A_PURGE_ENTER_RE_STATEMENTS'); ?><br />
+ <input type="text" name="re_string" value="" />
+ </td>
+ </tr>
+ </table>
+ </fieldset>
+ </form>
+ </div>
+ <div class="kadmin-footer">
+ <?php echo KunenaVersion::getLongVersionHTML (); ?>
+ </div>
+</div>
View
14 administrator/components/com_kunena/views/tools/view.html.php
@@ -50,6 +50,11 @@ function displayMenu() {
$this->display ();
}
+ function displayPurgeReStatements() {
+ $this->setToolBarPurgeReStatements();
+ $this->display ();
+ }
+
protected function setToolBarDefault() {
JToolBarHelper::title ( '&nbsp;', 'kunena.png' );
JToolBarHelper::spacer();
@@ -92,4 +97,13 @@ protected function setToolBarMenu() {
JToolBarHelper::back();
JToolBarHelper::spacer();
}
+
+ protected function setToolBarPurgeReStatements() {
+ JToolBarHelper::title ( '&nbsp;', 'kunena.png' );
+ JToolBarHelper::spacer();
+ JToolBarHelper::trash('purgerestatements', 'COM_KUNENA_A_PURGE_RE_MENU_VALIDATE', false);
+ JToolBarHelper::spacer();
+ JToolBarHelper::back();
+ JToolBarHelper::spacer();
+ }
}
Something went wrong with that request. Please try again.