Reputation: 8103
I'm writing a php script which will enable people to change the theme of their drupal website. So far, so good but one last thing I couldn't figure out. Every time when I submit the form, the database is changed but the theme doesn't change. Apparently, I have to clear the cache as well. I found this on the Drupal website:
<?php
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
drupal_flush_all_caches();
?>
I should make a little file 'clear.php' with this script, and every time I want to clear the cache, I should go to this file and the cache shout be cleared...
But their is my problem. I don't know how to call this page in my script. Sure I can make a button which will redirect the user to this page, but I'ld like it in one script.
Any idea's? Or are their other ways to flush the Drupal cache using php?
Thanks in advance!
Upvotes: 2
Views: 6465
Reputation: 5947
Open settings.php (/sites/default/settings.php) in any plain text editor. Add this line to the end of the file and save it:
$settings['rebuild_access'] = TRUE;
Upvotes: 0
Reputation: 347
Be careful with clearing your cache programmatically with mysql-statements.
This might break your entire drupal registry and you might end up with a blank page on drupal bootstrap so even drush might fail.
The only way fixing this is again is using "registry_rebuild" from here: https://drupal.org/project/registry_rebuild
I tried to clear the cache manually yesterday and ended up that way. I strongly suggest to keep using things like:
cache_clear_all(NULL, 'cache_page');
OR
drupal_flush_all_caches();
Upvotes: 0
Reputation: 8103
Tadaa, did it :)
Just paste this piece op php in my script:
$deletecachesql = "DELETE FROM cache";
$deletecachequery = mysql_query($deletecachesql) or die ("error").mysql_error();
$deletecacheresult = mysql_fetch_array($deletecachequery);
The script does clear the cache, but I'm not sure it's a good thing to do. The website also told me to delete:
Is it a wise thing to do? To clear (delete) the cache like this?
Upvotes: 1
Reputation: 9052
some tips:
drupal_flush_allcaches();
in the _submit hook of your form? then you don't need to bootstrap. Also you can create a menu entry with a function callback in a custom module with hook_menu and then put there your snippet. Again without need to bootstrap.
If really needs to be a separate script, put it in the root folder of your installation and then call mysite.com/clear.php
. If you put it somewhere else, you should change the path to bootstrap.inc (because it's a relative path)
cache_clear_all('theme_registry', 'cache', TRUE);
Upvotes: 3