CakePHP console gives error "Undefined index: HTTP_HOST" - cakephp-2.0

I have a setting in my APP/Config/config.php I have a line that defines the host:
define('SITE_URL','http://'.$_SERVER['HTTP_HOST']);
Whenever I run the cake console, I get the error:
Notice (8): Undefined index: HTTP_HOST [APP/Config/config.php, line 144]
Code Context
include - APP/Config/config.php, line 144
PhpReader::read() - CORE/Cake/Configure/PhpReader.php, line 80
Configure::load() - CORE/Cake/Core/Configure.php, line 267
include - APP/Config/bootstrap.php, line 190
Configure::bootstrap() - CORE/Cake/Core/Configure.php, line 92
require - CORE/Cake/bootstrap.php, line 146
ShellDispatcher::_bootstrap() - CORE/Cake/Console/ShellDispatcher.php, line 131
ShellDispatcher::_initEnvironment() - CORE/Cake/Console/ShellDispatcher.php, line 101
ShellDispatcher::__construct() - CORE/Cake/Console/ShellDispatcher.php, line 57
ShellDispatcher::run() - CORE/Cake/Console/ShellDispatcher.php, line 68
[main] - APP/Console/cake.php, line 33
Why is this appearing and how can I solve this problem?

Its because you are running from console, (cakePHP uses PHP-CLI)
$_SERVER['HTTP_HOST']
its only filled when running from a browser (web server)

#Braian is right.
You could do the following in your config file:
if(php_sapi_name() === 'cli') {
define('SITE_URL','http://{DEFAULT HOST HERE};
} else {
define('SITE_URL','http://'.$_SERVER['HTTP_HOST']);
}
Alternatively, you could query your database for a host setting of some sort - if your hosts are different based on the environment - and use Configure::write to set your config value before your console scripts main logic is run.

Related

JSON parse error on running `hugo` command

I'm trying to build a blog using Hugo. Every time I run the hugo command, I get this error
ERROR 2021/06/22 18:57:50 JSON parse error: expected comma character
or an array or object ending on line 52 and column 40
12: {
^
Total in 145 ms
Error: Error building site: failed to render pages: JSON parse error:
expected comma character or an array or object ending on line 52 and column 40
12: {
^
I suspect my project directory structure to be the problem but I'm open to more questions about the situation.
My project directory structure looks like
root-folder
--content
--posts
--my-first-post.md
--posts-again
--my-second-post.md
--my-third-post.md
--my-fourth-post.md
and all markdown files contain exactly the following
---
title: "Project"
date: 2021-06-22T18:09:26+01:00
draft: false
---
This is a post
When draft is set to true, I don't get the error when I run the hugo command. The error comes up when draft for any of the files in posts or posts-again is set to false
I have searched every file for a line 52 that I can understand but I cannot find any.
Where could this error be coming from and how can I resolve it?
hugo serve and hugo serve -D work fine, but hugo doesn't
hugo-PaperMod is missing a comma in a JSON block in layouts/partials/templates/schema_json.html
I got this error and just pushed up a PR to fix it
https://github.com/adityatelange/hugo-PaperMod/pull/614
this may be your issue
Issue is baseurl set to "/" in config.toml.
Change it to "" and try

SavedModel file does not exist when using Tensorflow hub

When trying to use the hub.load function from tensorflow_hub, I get an OSError: SavedModel file does not exist at: error.
The weird thing is that it worked a few days ago, so I don't quite understand why I'm getting this error now.
Code to reproduce:
import tensorflow as tf
import tensorflow_hub as hub
URL = 'https://tfhub.dev/google/universal-sentence-encoder/4'
embed = hub.load(URL)
Specific error received:
OSError Traceback (most recent call last)
<ipython-input-11-dfb80f0299b2> in <module>
1 URL = 'https://tfhub.dev/google/universal-sentence-encoder/4'
----> 2 embed = hub.load(URL)
~/opt/anaconda3/lib/python3.7/site-packages/tensorflow_hub/module_v2.py in load(handle, tags)
100 if tags is None and is_hub_module_v1:
101 tags = []
--> 102 obj = tf_v1.saved_model.load_v2(module_path, tags=tags)
103 obj._is_hub_module_v1 = is_hub_module_v1 # pylint: disable=protected-access
104 return obj
~/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in load(export_dir, tags)
576 ValueError: If `tags` don't match a MetaGraph in the SavedModel.
577 """
--> 578 return load_internal(export_dir, tags)
579
580
~/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in load_internal(export_dir, tags, loader_cls)
586 tags = nest.flatten(tags)
587 saved_model_proto, debug_info = (
--> 588 loader_impl.parse_saved_model_with_debug_info(export_dir))
589
590 if (len(saved_model_proto.meta_graphs) == 1 and
~/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/saved_model/loader_impl.py in parse_saved_model_with_debug_info(export_dir)
54 parsed. Missing graph debug info file is fine.
55 """
---> 56 saved_model = _parse_saved_model(export_dir)
57
58 debug_info_path = os.path.join(
~/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/saved_model/loader_impl.py in parse_saved_model(export_dir)
111 (export_dir,
112 constants.SAVED_MODEL_FILENAME_PBTXT,
--> 113 constants.SAVED_MODEL_FILENAME_PB))
114
115
OSError: SavedModel file does not exist at: /var/folders/77/rvfl368x44s51r8dc3b6l2rh0000gn/T/tfhub_modules/063d866c06683311b44b4992fd46003be952409c/{saved_model.pbtxt|saved_model.pb}
So, just deleting that folder and running the hub.load() function again solves the issue
I have tried the above solution, but it didn't work for me...
Here's what worked:
Download the model from tfhub.dev with assets, variables and .pb checkpoint file.
Make sure you import tensorflow_text module!
import tensorflow_text
Specify the downloaded folder path in the hub.load() statement as in:
model =
hub.load("/Users/bilguun/Desktop/universal-sentence-encoder-multilingual-large_3/")
I was using i3d = hub.load(https://tfhub.dev/deepmind/i3d-kinetics-400/1).signatures['default'] as shown here
This method of loading the model worked in that day but after a few days I got the same error: OSError: SavedModel file does not exist at: C:\Users\catal\AppData\Local\Temp\tfhub_modules\092225fb776e28d6d64ac605ab6be03f18dd2027{saved_model.pbtxt|saved_model.pb}
After doing some research, I understood that the saved_model file location (specified in the error) was temporary so even if that folder still exists, there is no more saved_model.pb in it. So I downloaded the model linked here: https://tfhub.dev/deepmind/i3d-kinetics-400/1 and set i3d = hub.load("C:\\absolute_path_to_saved_model_folder").signatures['default'] and it worked.
So using Bilguun's answer really helped in my case.
This kind of error happens because the downloaded model is saved in temporary folder created by the application.
Since it is a temporary folder, the model saved in it may gets deleted or even the folder can be deleted.
When calling the hub.load() command, the programme checks for the temporary folder, if the folder is not found, the program will download the data from internet.
But if the folder is found and the data(or model) is not there, instead of downloading from the internet, it raises an error.
It can be resolved by deleting the temporary folder completely.
In Mac the temporary folder can be accessed by the command "open $TMPDIR" on the terminal( reference : https://osxdaily.com/2018/08/17/where-temp-folder-mac-access/).
The name of the folder can be get from the raised error and can be deleted easily .

Drupal 7 - Theme Info Name Errors After Transferring Site to New Server

After transferring over a finished site to a new server, files/database and all, switching over the database settings in settings.php and running update.php I get the following errors:
Notice: Undefined index: name in block_menu() (line 146 of /home/nrsc2533/public_html/modules/block/block.module).
Notice: Undefined index: name in block_menu() (line 165 of /home/nrsc2533/public_html/modules/block/block.module).
Notice: Undefined index: name in system_menu() (line 647 of /home/nrsc2533/public_html/modules/system/system.module).
Notice: Undefined index: name in block_menu() (line 146 of /home/nrsc2533/public_html/modules/block/block.module).
Notice: Undefined index: name in block_menu() (line 165 of /home/nrsc2533/public_html/modules/block/block.module).
Notice: Undefined index: name in system_menu() (line 647 of /home/nrsc2533/public_html/modules/system/system.module).
I also lose most if not all of the items in the admin menu. I looked up the errors and they were all related to the following line of code:
'title' => check_plain($theme->info['name']),
This is a free theme that I customized, it is working fine on my test domain on my server, but not now that it has transferred. I did change the [theme].info file to reflect that it had been customized on the "name =" line. I checked online and found that the encoding may have been changed when I saved it, again strange since I had done this on the test domain and it seemed fine, so I changed the encoding to UTF-* without BOM and still to no avail. I have tried clearing the cache again via update.php and nothing changes. Any help will be GREATLY appreciated.

error parsing app.yaml for GAE/Java when specifying servlet for handler

I'm trying to switch over to using app.yaml instead of web.xml and app-engine-web.xml. I've attempted to follow the documentation faithfully, but I'm getting an error from appconfig.cmd update <my-war-directory> that says
Reading application configuration data...
Bad configuration: Line 18, column 13: Error setting property 'handlers' on class: com.google.apphosting.utils.config.AppYaml
Caused by: Line 18, column 13: Error setting property 'handlers' on class: com.google.apphosting.utils.config.AppYaml
Please see the logs [C:\Users\<blah blah>\appcfg3710135744474388957.log] for further information.
In the indicated log file, I see a stack dump with the line:
com.google.appengine.repackaged.net.sourceforge.yamlbeans.tokenizer.Tokenizer$TokenizerException: Line 18, column 13: Found a mapping value where it is not allowed.
Here's my file (with line numbers manually added):
1 application: my-app
2 version: 1
3 runtime: java
4 threadsafe: true
5
6 public_root: /static
7
8 static_files:
9 - include: /**
10
11 welcome_files:
12 - index.html
13
14 system_properties:
15 java.util.logging.config.file: WEB-INF/logging.properties
16
17 handlers:
18 - url: /user/*
19 servlet: org.restlet.ext.servlet.ServerServlet
20 name: user
21 init_params:
22 org.restlet.application: com.my-app.server.resource.user.UserApplication
23 org.restlet.clients: HTTP HTTPS
After experimenting with some YAML validators on the web, I actually think it is complaining about line 19, where column 13 points to the ":" character after "servlet". But this usage looks totally consistent with the documentation at https://developers.google.com/appengine/docs/java/configyaml/appconfig_yaml#Required_Elements
I'm sure I'm doing something stupid, but I'm stumped.
Thank you for your great input AndyD! The documentation is updated to fix the problematic sample code.
For me, it is also very convenient to use some yaml validator to check the yaml files. For example:
http://data-lint.herokuapp.com/
Thanks.
As I noted above, the culprit was the indentation of lines 19-21 - they need to line up under the "u" in "url" from line 18.

mongodb cakephp driver installation

I'm trying to get mongodb to work with cakephp. I'm not sure on where to place ichikaway's mongodb driver for cakephp and where to add the database connection.
My directory structure is that, under c:/websites/, I have cakephp folder and my project merry_flowers folder.
i've already gone through ichikaway's github and mark story's website.
If I put the mongodb driver in \cakephp\app\plugins and database connection in \cakephp\app\config\database.php
I'm getting the following error:
fatal error 256: ConnectionManager::loadDataSource - Unable to import DataSource class mongodb.mongodbSource [CORE\cake\libs\model\connection_manager.php, line 185]Code | Context
if (!App::import('Datasource', $class, !is_null($conn['plugin']))) {
trigger_error(sprintf(__('ConnectionManager::loadDataSource - Unable to import DataSource class %s', true), $class), E_USER_ERROR);$connName = "mongo"
$_this = ConnectionManager
ConnectionManager::$config = DATABASE_CONFIG object
ConnectionManager::$_dataSources = array
ConnectionManager::$_connectionsEnum = array
$conn = array(
"plugin" => "mongodb",
"classname" => "mongodbSource",
"parent" => array(
"filename" => "dbo_source",
"classname" => "DboSource",
"parent" => null,
"plugin" => null
),
"filename" => "dbo\mongodb_source"
)
$class = "mongodb.mongodbSource"ConnectionManager::loadDataSource() - CORE\cake\libs\model\connection_manager.php, line 185
ConnectionManager::getDataSource() - CORE\cake\libs\model\connection_manager.php, line 109
Model::setDataSource() - CORE\cake\libs\model\model.php, line 2836
Model::__construct() - CORE\cake\libs\model\model.php, line 469
ClassRegistry::init() - CORE\cake\libs\class_registry.php, line 142
Controller::loadModel() - CORE\cake\libs\controller\controller.php, line 637
Controller::constructClasses() - CORE\cake\libs\controller\controller.php, line 493
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 186
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
[main] - APP\webroot\index.php, line 87
If I put the mongodb driver in \merry_flowers\plugins and add the database connection to \merry_flowers\config\database.php, I'm getting the following error:
connecting to localhost:27017 failed: Unknown error APP\plugins\mongodb\models\datasources\mongodb_source.php, line 201
thank you.
It doesn't matter which plugins folder you use. Both have the same functionality. Both are included for your organizational convenience.
Do you have a mysql database set up also? If so, there might not be documentation for a dual installation. If you only have one DB, you should be configuring it in cakephp/app/config/database.php

Resources