1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Developer Tools

Discussion in 'XenForo Development Discussions' started by Robbo, Aug 15, 2012.

  1. Robbo

    Robbo Well-Known Member

    NOTE: this is currently alpha, use at your own risk... this has the potential to delete every template from your system if there is a bug (I did that in testing a while ago)

    XenForo Developer Tools is a set of tools I created for myself to remove a lot of the tedious things that come with developing with XenForo. It is designed to work in conjuction with XenForo-CLI (github.com/Naatan/XenForo-CLI/).

    Project Status
    Current features are subject to heavy change and could be plain old broke. These tools are designed to be used by developers on a development enviroment. When things are needed they will be added and pull requests will be considered.

    • Pear xattr package (http://pecl.php.net/package/xattr)
    • XenForo-CLI (github.com/Naatan/XenForo-CLI/) - not currently required but I expect it will be in the near future

    You have 2 options here. If you use XenForo-CLI simply go to your root directory and run "xf addon import https://github.com/Robbo-/XenForo-Developer-Tools.git" and it will clone, symlink, install and rebuild caches for you. If you don't use XenForo-CLI or it doesn't work for you (currently it is linux only and also in alpha stages) then you can simply clone the repository and install like any other add-on.

    Note: you need to do the changes that are in admin.new and index.new to your admin.php and index.php files.

    Current Features
    Currently the only feature of these tools is templates on the file system. Other will be created over time and are outlined below and in the TODO file.

    File System Templates
    Supports everything you would expect. Creating, deleting, updating contents, renaming and even changing the addon_id. After installation all templates will be written into rootDir/templates. Currently only admin and master templates are supported. So you will see files like templates/admin/XenForo/public.css. Each addon has it's own folder. So templates for this add-on will be located in templates/admin/devTools and templates/master/devTools. If you move a file from one add-on folder to another you will be changing the addon that template is with (like changing the dropbox from the ACP).

    How it works? Every page load it will scan the templates for new templates, renamed template or deleted templates. Then whenever a template is requested (usually each page load will request only a few) the last modified date is checked against a last updated time and the database is updated accordingly. From my tests this is all done very fast, especially compared to webdav.

    Some things don't work or could corrupt the whole system, I recommend you reading the source to understand how everything works at least a little. One thing to note is that when a file is created on the file system it is updated with extended attributes to add the template_id. What this means is if you delete a file on the file system but then save it again (from having it open elsewhere for example) it most likely won't have the template_id stored anymore and if no requests have been to a webpage in that time it will cause that file on the file system to simply not work with anything.

    Upcoming Features
    These tools are planned to do a lot more than what it does now... see the TODO file for a little insight into what I plan to add.
  2. Robbo

    Robbo Well-Known Member

    Chris D and Jake Bunce like this.
  3. Chris D

    Chris D XenForo Developer Staff Member

    I've downloaded.

    Might not be able to test this using WAMP as I can't see that there's a xattr version compatible with Windows.
  4. Robbo

    Robbo Well-Known Member

    Naatan is on MAMP and trying to get it to work. He will report back if he can otherwise I'll make changes.
    Chris D likes this.
  5. Naatan

    Naatan Well-Known Member

    Robbo just accepted my pull request which falls back on an alternative method of tracking template id's, making the xattr dependency optional.

    It also implements an alternative method for running the script which does not require you to edit index.php and admin.php. In theory it's install and use now but I haven't thoroughly tested it.
    Chris D likes this.
  6. Chris D

    Chris D XenForo Developer Staff Member

    Then I will try it and let you know :)
  7. Chris D

    Chris D XenForo Developer Staff Member

    Installer Problem:

    Fatal error: Using $this when not in object context in C:\wamp\www\xenforo\library\DevTools\Installer.php on line 21

    Was able to resolve by changing line 21 from:


  8. Naatan

    Naatan Well-Known Member

    Thanks, I'll fix it. You might want to do a fresh install to make sure the template files were properly created.
    Chris D likes this.
  9. Chris D

    Chris D XenForo Developer Staff Member

    I just did a pull request - more out of curiosity than anything - not used GitHub before :p
  10. Naatan

    Naatan Well-Known Member

    Damn I just pushed the fix shortly before you made the pull request :p
  11. Chris D

    Chris D XenForo Developer Staff Member

    That's ok - it was pointless me doing it for something so small. As I say, just curious :p
  12. Adam Howard

    Adam Howard Well-Known Member


    ..... I'm going to play with this a little.... Thanks for sharing :)
  13. Chris D

    Chris D XenForo Developer Staff Member

    Working good so far :)

    Well, I've only done one template edit, but it's nice not switching from Eclipse to Admin CP to Frontend.

    Being able to stay focussed on everything in one place is a huge help.
  14. Chris D

    Chris D XenForo Developer Staff Member

    A bit of feedback...

    I'm going to continue using it, but it does add about 2 seconds to each page load. So there's a bit of a trade off... You've got the poor performance of WebDAV compared to extra seconds on each page load.

    I think it's a small price to pay and it will vary dramatically dependent on the spec of your dev machine (I've got a pretty basic Intel Core i3 laptop running Windows 8 RC on WAMP) but it's worth bearing in mind. Especially to stop people thinking: **** my add-on now loads twice as slow!
  15. Naatan

    Naatan Well-Known Member

    Try installing APC. Also, what are your machines specs?

    Pages load instantly for me (within 200ms), so it's probably just a matter of configuration.


    Also, do you perhaps have a large amount of themes & addons installed? (like an excessive amount).
    Chris D likes this.
  16. Chris D

    Chris D XenForo Developer Staff Member

    As I say, it's just a basic Windows laptop so nothing special. It may very well run better on a decent server.
    I have no caching at all enabled on my dev machine either.

    I have 11 add-ons installed, only 5 enabled. Only have the Default Style installed too...

    I will test it on a beefier machine tomorrow and report back :)

    Going well, though, I like it.


    Have been wondering what happens after a template syntax error. Naturally, the changes are saved - nothing on the client side to prevent it of course.

    Not sure how you'd handle this, but I will tell you what the resulting error is anyway.

    e.g. template syntax error such as:

    {xen: raw $something}
    Results in:

    An exception occurred: file_get_contents(http://localhost/templatesync.php) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in C:\wamp\www\xenforo\library\DevTools\Listen.php on line 23
    file_get_contents() in DevTools/Listen.php at line 23
    call_user_func_array() in XenForo/CodeEvent.php at line 54
    XenForo_CodeEvent::fire() in XenForo/Application.php at line 376
    XenForo_Application::resolveDynamicClass() in XenForo/Route/Prefix.php at line 83
    XenForo_Route_Prefix->_loadAndRunSubRule() in XenForo/Route/Prefix.php at line 66
    XenForo_Route_Prefix->match() in XenForo/Router.php at line 61
    XenForo_Router->match() in XenForo/Dependencies/Public.php at line 141
    XenForo_Dependencies_Public->route() in XenForo/FrontController.php at line 261
    XenForo_FrontController->route() in XenForo/FrontController.php at line 128
    XenForo_FrontController->run() in C:/wamp/www/xenforo/index.php at line 13
  17. Naatan

    Naatan Well-Known Member

    I run my server on a 2010 Macbook Pro, so it's certainly not a super server either. Sounds like you have a configurations.

    For the record APC is NOT a caching solution, the caching functionality is a sub-feature of APC, it's main intend is to speed up PHP by compiling parts of your scripts.

    Error reporting has not really been implemented yet, keep in mind Robbo mentioned it's an alpha.
  18. Robbo

    Robbo Well-Known Member

    Errors will also work fine on linux if you use the first method where you edit admin.php and index.php to an extent.

    Also you keep saying people thinking your add-ons are slower due to this? This is by no means in any way designed to be run on a production server, it is for development only.

    About speed, all it does is scan the file system for changes which if you think about it a computer can do very fast so like Naatan said there must be something in your config slowing it down.
  19. Chris D

    Chris D XenForo Developer Staff Member

    I know it's an alpha. I'm testing your alpha and just feeding back stuff.

    I know that too :p But it was easier to refer to it as a cache in the context of me telling you I have no solution - caching or otherwise - in place.

    That's not what I meant, but I can see why you thought that.

    I know it's for development only. I'm using it in that context, and there was a short period of time last night where I stopped to wonder why the add-on I'm working on suddenly started taking three times longer to load. Turns out, it wasn't my add-on at all and the delay is caused by the Dev Tools add-on and the delay is around 2-3 seconds on every single XenForo page.

    Please don't take offence to what I'm saying - I've said loads of times the add-on is fantastic whether it be a 2ms delay or a 10 second delay on each page load. It works and I like it.

    I'm just telling you my current experience. It may well be that the problem is my end, but at least if someone else says the same thing you will have something to go on.

    Also the problem only happens when your add-on is the only one enabled still a 2 - 3 second increase on page load times (according to the debug mode output in the footer).

    I'm on a different PC today. I will install the dev tools here and report back.

    EDIT: For anyone considering trying this: PLEASE DO. It is actually a stroke of genius. (y)
  20. Robbo

    Robbo Well-Known Member

    2-3 second delays would be far too much for me though. It should never be that long unless a lot of templates have been modified at once in which case it will take a long time once (after those edits). I can't think of any reason for such a long delay :/ I won't be able to do any more work on this for a while as it is at a good enough state for me to get the Media Gallery done much more efficiently. However Naatan will most likely get annoyed by things like the lack of errors being displayed and push out some updates.
    Chris D likes this.

Share This Page