Created
October 30, 2013 23:51
-
-
Save alanpich/7242321 to your computer and use it in GitHub Desktop.
Rough example of de-databasing MODX elements (as far as humanly possible)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Rough outline script of extracting MODX elements from the database to | |
| * allow them to be version controlled. | |
| * | |
| * If this script is modified and also run for Snippets, Templates and Plugins | |
| * then you can start to VCS their source | |
| * | |
| * All that would remain would be triggering a cache-refresh after each deployment | |
| */ | |
| /** @var modX $modx MODX Instance */ | |
| // No preceding slash... | |
| $rootElementPath = 'path/relative/to/site/root'; | |
| // Grab all chunks | |
| foreach($modx->getCollection('modChunk') as $chunk){ | |
| /** @var modChunk $chunk */ | |
| // Create a file to store in | |
| $fileName = $chunk->get('name'). '.chunk.txt'; | |
| $filePath = $rootElementPath.DIRECTORY_SEPARATOR. $fileName; | |
| // Set chunk as static | |
| $chunk->set('static',true); | |
| $chunk->set('static_file',$filePath); | |
| $chunk->set('source',1); | |
| // Write db content to file | |
| $content = $chunk->get('snippet'); // Yes, i know is a stupid name, what can ya do... | |
| file_put_contents($filePath,$content); | |
| $chunk->save(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment