roryg / ElementHelper

Element Helper is a MODx Revolution plugin for automatically creating elements from static files without the MODx manager.
27 stars 10 forks source link

ElementHelper 2.0 #31

Open roryg opened 10 years ago

roryg commented 10 years ago

ElementHelper 2 is now up on the 2.0 branch, it's not quite finished yet but you can download a transport package for it here (tested and working on Revo 2.3.1). The code has been completely reworked/refactored and I think is much easier to work with now.

One of the biggest differences feature wise is that elements will now be synced both ways, so if you create an element in the manager a static file will be created for the element and vice versa. (This doesn't work for template variable elements to the template_variables.json file yet.)

There are a number of things still left to do:

  1. Template variables need to be saved/removed into/from the template_variables.json file when created/deleted in the manager.
  2. Add ability to create MIGx template variables
  3. Create tests!
  4. Decide if a setting for tv template access is needed.
  5. Decide if a setting for auto removing elements is needed.
  6. Since elements are synced both ways now there needs to be a way to prevent certain elements from being synced (e.g. a snippet or plugin that's installed with an extra).
  7. And probably a bunch of other things I'm forgetting! Feel free to discuss ideas, thoughts etc for 2.0 here.
DESIGNfromWITHIN commented 10 years ago

For me it is not working at fully.... 2.3.1 on localhost...

It is creating categories and if I create a chunk in the manager a file get created, but if I create a file, it does not create a chunk in MODX...

Snippets and plugins are also not created for me..

Template variables are working fine.

I got the following errors on install, might be the issue?

Error 42S22 executing statement: Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'modPluginEvent.name' in 'where clause' ) 
INSERT INTO `modx_site_plugin_events` (`pluginid`, `event`, `priority`, `propertyset`) VALUES (:pluginid, :event, :priority, :propertyset) Array ( [/:pluginid\b/] => 1 [/:event\b/] => '' [/:priority\b/] => 0 [/:propertyset\b/] => 0 ) 
Error 23000 executing statement: INSERT INTO `modx_site_plugin_events` (`pluginid`, `event`, `priority`, `propertyset`) VALUES (1, '', 0, 0) Array ( [0] => 23000 [1] => 1062 [2] => Duplicate entry '1-' for key 'PRIMARY' ) 
Error saving vehicle object of class modPluginEvent; criteria: Array ( [name] => ) 
Error 42S22 executing statement: Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'modPluginEvent.name' in 'where clause' ) 
INSERT INTO `modx_site_plugin_events` (`pluginid`, `event`, `priority`, `propertyset`) VALUES (:pluginid, :event, :priority, :propertyset) Array ( [/:pluginid\b/] => 1 [/:event\b/] => '' [/:priority\b/] => 0 [/:propertyset\b/] => 0 ) 
Error 23000 executing statement: INSERT INTO `modx_site_plugin_events` (`pluginid`, `event`, `priority`, `propertyset`) VALUES (1, '', 0, 0) Array ( [0] => 23000 [1] => 1062 [2] => Duplicate entry '1-' for key 'PRIMARY' ) 
Error saving vehicle object of class modPluginEvent; criteria: Array ( [name] => ) 
Could not install related objects with locally owned keys for vehicle object of class modPlugin; criteria: Array ( [name] => ElementHelper ) 
DESIGNfromWITHIN commented 10 years ago

UPDATE!

So it does not work with names like this:

chunkname.chunk.tpl
snippetname.snippet.php

This works fine

chunkname.tpl
snippetname.php
hugopeek commented 10 years ago

One thing I'm finding a bit tricky still, is renaming templates.. I want these names to be as clear as possible for clients, so sometimes I change their names to be more descriptive. To do that, you have to disable ElementHelper (to keep ID's the same), change filename to match, and change all template_access references in template_variables.json..

A bit cumbersome. Might it be possible to reference templates by ID for example, and add the name the same way you add a description?

Btw: can confirm that EH works the same as above here on localhost with 2.3.1. Same installation errors too..

JayCarney commented 10 years ago

@hugopeek I'm in the same boat in terms of needing to rename templates for clients, I just don't see a clean way to achieve the behaviour, I think you need to maintain the filename == template_name relationship

hugopeek commented 10 years ago

@JayCarney Thanks. Can imagine how that would be difficult to implement. Will survive without it though ;)

exside commented 10 years ago

@JayCarney & @hugopeek I'm also doing this quite often and never had to disable ElementHelper (at least when I'm the only Admin in the system), ElementHelper just runs for specified user groups (system settings), by default only members of Administrator, so if you need to rename a template, just rename it first in the tree, then rename the file on the server and after that reload the manger page (but don't do it inbetween!), I'm not really using the TV JSON feature, so problems coming from there are not considered in this "workflow". Had a quick scan trough the new code, and would like to say NICE WORK @roryg, looks much cleaner! But did no testing for functionality yet...

roryg commented 10 years ago

@DESIGNfromWITHIN Nice catch, I've just fixed it so you can include dots in element file names now. The install errors are unrelated but will need to be fixed too!

@hugopeek That's a good point, I'll have to think about the best way to achieve that. Adding the ID to a doc comment at the top of the template files might be a possibility but that would mean having something like the following at the top of each template file:

<?php /**
*
* @ID 7
*
*/ ?>

Perhaps that's too much clutter though?

@exside Cheers!

Qaraqter commented 9 years ago

@roryg I wouldn't mind that, but other users might find that to be too much clutter, yes.. Perhaps control this with a system setting?

I also found a little quirk when re-installing on 2.3.1: it didn't set the system events of the plugin (onWebPageInit and onManagerPageInit).

And another question: EH automatically makes all snippets static now too.. Will this be OK when you update the snippets that were installed through package manager? Or are there scenario's imaginable when the old static file would override the updated database entry?

(@qaraqter = @hugopeek btw ;))

DESIGNfromWITHIN commented 9 years ago

I found a big issue!

When I use the latest version of Element Helper snippets like Wayfinder become static and get comments on top of the file... This actually breaks the functionality!

roryg commented 9 years ago

Thanks @DESIGNfromWITHIN @Qaraqter I've made a note of both issues, I haven't had much time to work on it the past couple of weeks but should be able to sort these bugs out hopefully next weekish.

Just as a word of caution the plugin hasn't been heavily tested yet and is expected to have several bugs so if you're using it with your work beyond just testing it I would advise keeping regular backups! If you'd like it to ignore plugins and snippets you could try changing the respective paths in the settings to a directory that doesn't exist.

kevinhamil commented 9 years ago

@roryg I've just recently switched to a MODx setup and came across EH when searching best workflows... seeing the last discussion was 7 months ago, I was curious to find out if you've had any additional time to further develop this? I have the current version running and I love it, but of course, I am looking forward to a production release. Thanks.

roryg commented 9 years ago

@kevinhamil Yikes time flies! Apologies to all for neglecting this so badly, I'm definitely not abandoning it. I have projects coming up that I'll need ElementHelper for so I will be working on it soon.

roryg commented 9 years ago

Minor update available here - https://db.tt/SBKhONkV

Template Variables will now sync both ways including MIGX tvs. Unfortunately I haven't come up with a good way to sync template variable changes that have been made in the manager yet as Modx doesn't store a timestamp for them, but new TVs made in the manager will be synced to the TV json file.

kevinhamil commented 9 years ago

@roryg awesome, great news! Thanks.

kevinhamil commented 9 years ago

I don't know if this is the place to post a question like this, but I'm not sure where else it would be relevant to ask. In the template_variable.json, how would I define a specific Media Source? I can't seem to find how this would be included, or if it can be.

Something like... "media_source": ["myTVMediaSource"]

If there's a more appropriate place to ask questions like this let me know. Thanks.

roryg commented 9 years ago

@kevinhamil There's no way to do that yet but it's definitely a feature I want to include.

roryg commented 9 years ago

Updated package available here - https://www.dropbox.com/s/8nn1s6k162ynov6/elementhelper-2.0.0-alpha-2.transport.zip?dl=0

I've added a setting for controlling template variable access and fixed the installation errors people were having. I've also added a category whitelist setting which allows you to whitelist categories for ElementHelper to work with. This should help prevent tracking elements that have been created by other Modx extras.

DESIGNfromWITHIN commented 8 years ago

Any update on this? Can it be made available from within MODX?

roryg commented 8 years ago

It's almost ready to be available within Modx but there was an issue reported here - https://github.com/roryg/ElementHelper/issues/38 - that I'll need to work out first. Hopefully before the year ends!

jchirschy commented 8 years ago

Hello @roryg,

I definitely second th request from @kevinhamil. I have a huge using of media source for TV. It's a convenient way to guide the user through the tree of files. Would that feature be available with this new release ?

roryg commented 8 years ago

@jchirschy Yes, it's actually already available in the latest alpha version which you can find here - https://www.dropbox.com/s/5x627zz1cnq1rxw/elementhelper-2.0.0-alpha-3.transport.zip?dl=0 - it probably needs further testing but should hopefully work :)

Using it you add a media source to your TV json with the media_source property e.g. "media_source": "Uploads".

Izacktly commented 8 years ago

Hello @roryg I must say this is a great plugin. I installed from the test build posted above for Modx 2.4.2 However, the error log reports (ERROR @ /manager/index.php) [OnManagerPageInit]. and right after this the log prints the entire code from the articles plugin. If I remove the articles extra, it then starts reporting on the Ace plugin and so on. Anyone experiencing this?

roryg commented 8 years ago

Hi @Izacktly try adding the plugins causing the issues to the Element Blacklist setting, that should prevent ElementHelper from trying to process them. You might need to uninstall and reinstall the plugins after you've done that.

Izacktly commented 8 years ago

Understood. Thank you very much for the quick response!