Resource icon

Post Content Find / Replace 2.0.1

No permission to download

Chris D

XenForo developer
Staff member
Thank you!

Does the 'Save Changes' checkbox execute it? So leaving this unchecked is a way to test regex without executing write to the database?
 
Ran a query with 'Save Changes' unchecked and it looked good. Checked 'Save Changes' and ran it again, got this error:

Code:
An exception occurred: [Error] Call to undefined method XF\Service\Post\Editor::setIsAutomated() in src/addons/XFPR/Admin/Controller/PostReplace.php on line 54

XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 249
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 88
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1831
XF\App->run() in src/XF.php at line 328
XF::runApp() in admin.php at line 13

See this in Server Log:

Code:
Server error log
Error: Call to undefined method XF\Service\Post\Editor::setIsAutomated() src/addons/XFPR/Admin/Controller/PostReplace.php:54
Generated by: admin Oct 19, 2017 at 3:42 AM

Stack trace
#0 src/XF/Mvc/Dispatcher.php(249): XFPR\Admin\Controller\PostReplace->actionReplace(Object(XF\Mvc\ParameterBag))
#1 src/XF/Mvc/Dispatcher.php(88): XF\Mvc\Dispatcher->dispatchClass('XFPR:PostReplac...', 'Replace', 'html', Object(XF\Mvc\ParameterBag), '', Object(XFPR\Admin\Controller\PostReplace), NULL)
#2 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#3 src/XF/App.php(1831): XF\Mvc\Dispatcher->run()
#4 src/XF.php(328): XF\App->run()
#5 admin.php(13): XF::runApp('XF\\Admin\\App')
#6 {main}

Request state
array(4) {
  ["url"] => string(37) "/forum/admin.php?post-replace/replace"
  ["referrer"] => string(67) "https://www.photoshopgurus.com/forum/admin.php?post-replace/replace"
  ["_GET"] => array(1) {
    ["post-replace/replace"] => string(0) ""
  }
  ["_POST"] => array(5) {
    ["quick_find"] => string(6) "[video"
    ["regex"] => string(53) "#\[video=youtube;([a-z0-9_-]{11})][^\[]+\[/video]#siu"
    ["replace"] => string(25) "[media=youtube]\1[/media]"
    ["commit"] => string(1) "1"
    ["_xfToken"] => string(8) "********"
  }
}
 
Last edited:
Sorry, my bad. I'll actually release an update shortly but that will only restrict it from being installed on < Beta 7.

In the file src/addons/XFPR/Admin/Controller/PostReplace.php find:
PHP:
$editor->setIsAutomated();
And replace with:
PHP:
// $editor->setIsAutomated();
 
Thanks @Chris D

I commented that line as indicated, rebuilt the addon, ran it again and I get this now:

Code:
LogicException: Cannot save with validation errors. Use validate() to ensure there are no errors. (First error: Please enter a message with no more than 5 pieces of media.) in src/XF/Service/ValidateAndSavableTrait.php at line 34
XF\Service\Post\Editor->save() in src/addons/XFPR/Admin/Controller/PostReplace.php at line 59
XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 249
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 88
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1831
XF\App->run() in src/XF.php at line 328
XF::runApp() in admin.php at line 13

Server Error Log:

Code:
Server error log
LogicException: Cannot save with validation errors. Use validate() to ensure there are no errors. (First error: Please enter a message with no more than 5 pieces of media.) src/XF/Service/ValidateAndSavableTrait.php:34
Generated by: admin Oct 19, 2017 at 4:01 AM
Stack trace
#0 src/addons/XFPR/Admin/Controller/PostReplace.php(59): XF\Service\Post\Editor->save()
#1 src/XF/Mvc/Dispatcher.php(249): XFPR\Admin\Controller\PostReplace->actionReplace(Object(XF\Mvc\ParameterBag))
#2 src/XF/Mvc/Dispatcher.php(88): XF\Mvc\Dispatcher->dispatchClass('XFPR:PostReplac...', 'Replace', 'html', Object(XF\Mvc\ParameterBag), '', Object(XFPR\Admin\Controller\PostReplace), NULL)
#3 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#4 src/XF/App.php(1831): XF\Mvc\Dispatcher->run()
#5 src/XF.php(328): XF\App->run()
#6 admin.php(13): XF::runApp('XF\\Admin\\App')
#7 {main}
Request state
array(4) {
  ["url"] => string(37) "/forum/admin.php?post-replace/replace"
  ["referrer"] => string(67) "https://www.photoshopgurus.com/forum/admin.php?post-replace/replace"
  ["_GET"] => array(1) {
    ["post-replace/replace"] => string(0) ""
  }
  ["_POST"] => array(5) {
    ["quick_find"] => string(6) "[video"
    ["regex"] => string(53) "#\[video=youtube;([a-z0-9_-]{11})][^\[]+\[/video]#siu"
    ["replace"] => string(25) "[media=youtube]\1[/media]"
    ["commit"] => string(1) "1"
    ["_xfToken"] => string(8) "********"
  }
 
This is where Beta 7 will help as it will ignore that error.

But basically you have your max Media per message option set to 5, but one of the posts being edited contains more than 5.

Probably worth just setting that to 0 (for no limit) for now and that should sort it.
 
Last edited:
I updated to Beta 7 and uploaded the new version of this addon. I'm unable to run the addon updater, it says:

The following errors must be resolved before continuing:
  • Post Content Find / Replace requires XenForo 2.0.0 Beta 7+.
Doesn't seem to recognize I am running Beta 7.
 
Last edited:
Hi,

I found 34 item with my regex, but after clic on button to save, i have this error :
Code:
InvalidArgumentException: Attempted to convert NULL to string/binary [content_title] in src/XF/Mvc/Entity/Entity.php at line 685
XF\Mvc\Entity\Entity->_castValueToType() in src/XF/Mvc/Entity/Entity.php at line 572
XF\Mvc\Entity\Entity->set() in src/XF/Mvc/Entity/Entity.php at line 502
XF\Mvc\Entity\Entity->__set() in src/XF/ModeratorLog/Post.php at line 60
XF\ModeratorLog\Post->setupLogEntityContent() in src/XF/ModeratorLog/AbstractHandler.php at line 67
XF\ModeratorLog\AbstractHandler->log() in src/XF/ModeratorLog/AbstractHandler.php at line 47
XF\ModeratorLog\AbstractHandler->logChange() in src/XF/ModeratorLog/Logger.php at line 62
XF\ModeratorLog\Logger->logChanges() in src/XF/Logger.php at line 47
XF\Logger->logModeratorChanges() in src/XF/Entity/Post.php at line 502
XF\Entity\Post->_postSave() in src/XF/Mvc/Entity/Entity.php at line 1137
XF\Mvc\Entity\Entity->save() in src/XF/Service/Post/Editor.php at line 165
XF\Service\Post\Editor->_save() in src/XF/Service/ValidateAndSavableTrait.php at line 40
XF\Service\Post\Editor->save() in src/addons/XFPR/Admin/Controller/PostReplace.php at line 59
XFPR\Admin\Controller\PostReplace->actionReplace() in src/XF/Mvc/Dispatcher.php at line 249
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1879
XF\App->run() in src/XF.php at line 328
XF::runApp() in admin.php at line 13
 
Hi, I tried to install this on XF 2.0.2 and it says:

Confirm action
We found some errors while trying to install the following add-on:Post Content Find / Replace 2.0.1
The following errors must be resolved before continuing:
  • Post Content Find / Replace requires XenForo 2.0.0 Beta 7+.
It probably doesn't recognize that 2.0.2 is actually newer than 2.0.0 b7.
 
Well versions are compared based on a numeric ID. Version 2.0.2 is 2000270 and version 2.0.0 Beta 7 is 2000037 and 2000270 is definitely greater than 2000037.

I've just tested this locally and it seems to work fine.

The only possible cause for it not working as far as I can tell is the addOns cache which is in the xf_data_registry table being incorrect.

Could you run this query on your database and let me know the value returned, please? It might be quite long depending on how many add-ons you have enabled:
SQL:
SELECT CAST(data_value AS CHAR) AS data_value
FROM xf_data_registry
WHERE data_key = 'addOns'
 
Well versions are compared based on a numeric ID. Version 2.0.2 is 2000270 and version 2.0.0 Beta 7 is 2000037 and 2000270 is definitely greater than 2000037.

I've just tested this locally and it seems to work fine.

The only possible cause for it not working as far as I can tell is the addOns cache which is in the xf_data_registry table being incorrect.

Could you run this query on your database and let me know the value returned, please? It might be quite long depending on how many add-ons you have enabled:
SQL:
SELECT CAST(data_value AS CHAR) AS data_value
FROM xf_data_registry
WHERE data_key = 'addOns'

Code:
mysql> SELECT CAST(data_value AS CHAR) AS data_value
    -> FROM xf_data_registry
    -> WHERE data_key = 'addOns';
+---------------------------+
| data_value                |
+---------------------------+
| a:1:{s:2:"XF";i:2000010;} |
+---------------------------+
1 row in set (0.00 sec)

Note that we had the XF1 version of this addon installed before. But I have uninstalled prior to the upgrade to XF2.
 
Ok, well there's the problem, as that value suggests you're running XF 2.0.0 Alpha. Which actually could be a bug.

What's the result of this query?
SQL:
SELECT version_id
FROM xf_addon
WHERE addon_id = 'XF'
 
And this one for good measure:
SQL:
SELECT version_id
FROM xf_upgrade_log
ORDER BY completion_date DESC
 
Top Bottom