I created the following script and put it to cron job on server. Unfortunately it does not work.
include 'includes/defines.php';
include 'includes/framework.php';
$conf = JFactory::getConfig();
$options = array(
'defaultgroup' => '',
'storage' => $conf->get('cache_handler', ''),
'caching' => true,
'cachebase' => $conf->get('cache_path', JPATH_SITE . '/cache')
);
$cache = JCache::getInstance('', $options);
$cache->clean('cachegroup');
Do you have an idea what is wrong?
Related
I'm working on a Drupal 8 starter kit with Composer, similar to drupal-composer/drupal-project.
In my post-install script, I want to re-generate a settings.php file with my custom values.
I've seen that can be done with the drupal_rewrite_settings function.
For example, I'm rewriting the config_sync_directory value like that :
require_once $drupalRoot . '/core/includes/bootstrap.inc';
require_once $drupalRoot . '/core/includes/install.inc';
new Settings([]);
$settings['settings']['config_sync_directory'] = (object) [
'value' => '../config/sync',
'required' => TRUE,
];
drupal_rewrite_settings($settings, $drupalRoot . '/sites/default/settings.php');
Problem is I want my Drupal 8 project to have a Dotenv so the maintainers don't have to modify the settings.php but only a .env file in the root folder of the project. To make it work, my settings.php must look like this :
$databases['default']['default'] = [
'database' => getenv('MYSQL_DATABASE'),
'driver' => 'mysql',
'host' => getenv('MYSQL_HOSTNAME'),
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'password' => getenv('MYSQL_PASSWORD'),
'port' => '',
'prefix' => '',
'username' => getenv('MYSQL_USER'),
];
$settings['trusted_host_patterns'] = explode(',', '^'.getenv('SITE_URL').'$');
As you can see, the values are replaced by PHP functions, and I can't see a good way to print those values, to the point I'm not even sure that's possible.
So my question is : is it possible to escape a PHP function as an Array value when declaring this variable ?
Looks like it's not possible because of the way the Drupal function works.
Solution 1 by #misorude
Using the drupal_rewrite_settings function, we can add the value of settings as a String, like this :
$settings['settings']['trusted_host_patterns'] = (object) [
'value' => "FUNC[explode(',', '^'.getenv('SITE_URL').'$')]",
'required' => TRUE,
];
And after that, we can replace all occurrences of "FUNC[***]" by *** directly in the settings.php file.
Solution 2
Put all your settings in a separate file. Example here, a custom.settings.php file :
if (getenv('DEBUG') == 'true') {
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/dev.services.yml';
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
}
$databases['default']['default'] = [
'database' => getenv('MYSQL_DATABASE'),
'driver' => 'mysql',
'host' => getenv('MYSQL_HOSTNAME'),
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'password' => getenv('MYSQL_PASSWORD'),
'port' => '',
'prefix' => '',
'username' => getenv('MYSQL_USER'),
];
$settings['trusted_host_patterns'] = explode(',', '^'.getenv('SITE_URL').'$');
$settings['file_private_path'] = 'sites/default/files/private';
$settings['config_sync_directory'] = '../config/sync';
Then we can copy the default.settings.php and add our custom settings.
$fs = new Filesystem();
$settings_generated = $drupalRoot . '/sites/default/settings.php';
$settings_default = $drupalRoot . '/sites/default/default.settings.php';
$settings_custom = $drupalRoot . '/../includes/custom.settings.php';
$fs->remove($settings_generated);
$fs->dumpFile($settings_generated, file_get_contents($settings_default) . file_get_contents($settings_custom));
There's also a appendToFile method that seems way better than dumping a new file with dumpFile, but it was not working unfortunatly.
I am working on optimizing Zend Framework Application with Doctrine ORM. I can't figure it out what particular code would I use in my controller to get this caching. Whenever I pass again the same url it should use the cache code instead of processing that logic again.
My Bootstrap file for cache looks like this:-
protected function _initCache() {
$frontendOptions = array(
'lifetime' => 7200, 'content_type_memorization' => true,
'default_options' => array(
'cache' => true,
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'cache_with_session_variables' => true,
'cache_with_cookie_variables' => true, ),
'regexps' => array(
// cache the whole IndexController
'^/.*' => array('cache' => true),
'^/index/' => array('cache' => true),
// place more controller links here to cache them
)
);
$backendOptions = array(
'cache_dir' => APPLICATION_PATH ."/../cache" // Directory where to put the cache files
);
$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
$cache->start();
Zend_Registry::set("cache", $cache);
}
Any help would be appreciated.
Check this below code to set cache if not exist or get cache if exists.
$result =””;
$cache = Zend_Registry::get('cache');
if(!$result = $cache->load('mydata')) {
echo 'caching the data…..';
$data=array(1,2,3); // demo data which you want to store in cache
$cache->save($data, 'mydata');
} else {
echo 'retrieving cache data…….';
Zend_Debug::dump($result);
}
For some reason, PHP crashes when I try to open a page. I am using localhost:82 in Uniform Server Zero.
The code is as follows:
index.php
<?php
require_once 'core/init.php';
$db = new DB();
?>
core/init.php
<?php
session_start();
$GLOBALS['config'] = array(
'mysql' => array(
'host' => 'localhost:82',
'username' => 'root',
'password' => 'password',
'db' => 'forum'
),
'remember' => array(
'coolie_name' => 'hash',
'cookie_expiry' => 604800
),
'session' => array(
'session_name' => 'user'
)
);
spl_autoload_register(function($class) {
require_once '../classes/' . $class . '.php';
});
require_once '../functions/sanitize.php';
?>
functions/sanitize.php
<?php
function escape($string) {
return htmlentities($string, ENT_QUOTES, 'UTF-8');
}
?>
I tried adding the text test before and after each of the php tags, and it seems that only index.php crashes (It displays the test text before the php tags, but not after - even in View Source mode).
The browser I am using is the Aurora dev version, and I am getting the code from this youtube tutorial.
I'm having some problems while trying to get phalcon webtools working.
When using command line devtools I can create controllers and models without problems.
However, things aren't that easy with the webtools.
It correctly shows already created controllers and models:
Controllers (http://i.imgur.com/IRWPaVJ.png)
Models (http://i.imgur.com/rIbvbg9.png)
And I can also edit them (http://i.imgur.com/orJweLl.png).
Apparently, Db connexion is ok, since webtools shows every table in the DB:
Models (http://i.imgur.com/iOkZfyo.png)
Scaffolding (http://i.imgur.com/5ZLRuq5.png)
However, when trying to create a controller from the web interface, I got the next error:
"Please specify a controller directory"
Same when trying to create a Model from a database table :
"Database configuration cannot be loaded from your config file"
Or when trying to generate scaffold :
"Adapter was not found in the config. Please specify a config variable
[database][adapter]"
My app/config/config.php content:
return new \Phalcon\Config(array(
'database' => array(
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'phalcon',
'password' => 'phalcon',
'dbname' => 'phalcon',
'charset' => 'utf8',
),
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
'viewsDir' => __DIR__ . '/../../app/views/',
'pluginsDir' => __DIR__ . '/../../app/plugins/',
'libraryDir' => __DIR__ . '/../../app/library/',
'cacheDir' => __DIR__ . '/../../app/cache/',
'baseUri' => '/phalconTest/',
)
));
My public/webtools.config.php content:
define('PTOOLS_IP', '192.168.248.135');
define('PTOOLSPATH', 'C:/phalcon-devtools');
My public/webtools.php:
use Phalcon\Web\Tools;
require 'webtools.config.php';
require PTOOLSPATH . '/scripts/Phalcon/Web/Tools.php';
Tools::main(PTOOLSPATH, PTOOLS_IP);
Im running Phalcon 1.3.4 - Windows x86 for PHP 5.4.0 (VC9)
It seems like a bug in webtools.
Look at vendor/phalcon/devtools/scripts/Phalcon/Builder/Component.php
there is the _getConfig function.
The quick and dirty solution is prepend ../ to path.
You need to change the first line in app/config/config.php
defined('APP_PATH') || define('APP_PATH', realpath('..'));
To add to some of the answers, the editing of configPath by prepending ../ and also some code changes, has forgotten a a little '/' when modelPath has been rtrimmed.
Also, code will be updated and fixed but as of now, one can probably fix the issues by editing your/path/phalcon-devtools/scripts/Phalcon/Builder/Model.php; find
$modelsDir = rtrim(rtrim($modelsDir, '/'), '\\') . DIRECTORY_SEPARATOR;
if ($this->isAbsolutePath($modelsDir) == false) {
$modelPath = $path . DIRECTORY_SEPARATOR . $modelsDir;
} else {
// $modelPath = $modelsDir;
// replace or ADD TO LINE ABOVE so it looks like BELOW:
$modelPath = DIRECTORY_SEPARATOR . $modelsDir;
}
Then Models will work in webtools along with TKF's answer. Enjoy.
Apply changes in webtools.config.php like here:
<?php
if (!defined('PTOOLS_IP'))
define('PTOOLS_IP', '192.168.');
if (!defined('PTOOLSPATH'))
define('PTOOLSPATH', '/path/to/phalcon/devtools');
return array(
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
),
'database' => array(
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'usr',
'password' => 'pwd',
'dbname' => 'dbname',
)
);
Somewhat related, I had an issue with the webtools url getting longer and longer .. Eventually I could fix this by adding the word webtools in a replacement for the baseUri in config.php .
<?php ### config.php ... somewhat relevant parts ...
return new \Phalcon\Config([
'database' => [ # ... some things ...
],
'application' => [ # ... some more ...
// This allows the baseUri to be understand project paths that are not in the root directory
// of the webpspace. This will break if the public/index.php entry point is moved or
// possibly if the web server rewrite rules are changed. This can also be set to a static path.
'baseUri' => preg_replace(
'/(public([\/\\\\]))?(index)|(webtools).php$/',
'',
$_SERVER["PHP_SELF"]
),
]
]);
I just installed zend developer tools module and BjyProfiler module in my application. Zend developer tools is working fine and both zend developer tools module and BjyProfiler module showing in module list in toolbar. But BjyProfiler not working properly, when i click database button of zend developers toolbar then it show like following:
I go through BjyProfiler readme in github. After reading readme, I am not sure where to put this code to enable BjyProfiler for query debugging.
$profiler = $sl->get('Zend\Db\Adapter\Adapter')->getProfiler();
$queryProfiles = $profiler->getQueryProfiles();
In summary, my problem is where to put this code and how to enable BjyProfiler successfully to debug query error. Thanks for your kind attention.
Add to aplication.config.php:
'modules' => array(
//...
'BjyProfiler',
'ZendDeveloperTools',
'MyOtherModule',
//...
),
Create bjyprofiler.local.php in config/autoload & add:
$dbParams = array(
'database' => 'ZF2sample',
'username' => 'root',
'password' => '123456',
'hostname' => 'localhost',
// buffer_results - only for mysqli buffered queries, skip for others
'options' => array('buffer_results' => true)
);
return array(
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) {
$adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter(array(
'driver' => 'pdo',
'dsn' => 'mysql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'],
'database' => $dbParams['database'],
'username' => $dbParams['username'],
'password' => $dbParams['password'],
'hostname' => $dbParams['hostname'],
));
if (php_sapi_name() == 'cli') {
$logger = new Zend\Log\Logger();
// write queries profiling info to stdout in CLI mode
$writer = new Zend\Log\Writer\Stream('php://output');
$logger->addWriter($writer, Zend\Log\Logger::DEBUG);
$adapter->setProfiler(new BjyProfiler\Db\Profiler\LoggingProfiler($logger));
} else {
$adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler());
}
if (isset($dbParams['options']) && is_array($dbParams['options'])) {
$options = $dbParams['options'];
} else {
$options = array();
}
$adapter->injectProfilingStatementPrototype($options);
return $adapter;
},
),
),
);
F5 in browser!