Internal error when setting up cache - fat-free-framework

Im trying to set the cache for my app.
My problem is that I get error 500 when Im trying to use it.
This is my code:
<?php
include_once '/var/www/libs/mainCache/fatfree-master/lib/base.php';
class CacheManager
{
private $cache;
private $isDebug;
const GYM_LIST = "gym_list";
const CHALLENGES_LIST = "challnges_list";
function __construct($isDebug = false)
{
$this->cache = \Cache::instance();
$this->isDebug = $isDebug;
$folder = $this->isDebug ? "/var/www/soFitTest/cache/" : "/var/www/soFit/cache/";
$this->cache->load(true, "folder=".$folder);
}
public function exists($id)
{
return $this->cache->exists($id);
}
public function set($id, $value)
{
return $this->cache->set($id, $value);
}
public function get($id)
{
return $this->cache->get($id);
}
public function clear($id)
{
return $this->cache->clear($id);
}
}
When I run my code:
$cacheManager = new CacheManager(true);
$gmyList = $cacheManager->get(CacheManager::GYM_LIST);
if($gmyList)
{
$result = $gmyList;
$result["cache"] = "true";
}
else
{
$result = $gymManager->getGymsList();
$result["cache"] = "false";
$cacheManager->set(CacheManager::GYM_LIST, $result);
}
I get:
<!DOCTYPE html>
<html>
<head>
<title>500 Internal Server Error</title>
<style>code{word-wrap:break-word;color:black}.comment,.doc_comment,.ml_comment{color:dimgray;font-style:italic}.variable{color:blueviolet}.const,.constant_encapsed_string,.class_c,.dir,.file,.func_c,.halt_compiler,.line,.method_c,.lnumber,.dnumber{color:crimson}.string,.and_equal,.boolean_and,.boolean_or,.concat_equal,.dec,.div_equal,.inc,.is_equal,.is_greater_or_equal,.is_identical,.is_not_equal,.is_not_identical,.is_smaller_or_equal,.logical_and,.logical_or,.logical_xor,.minus_equal,.mod_equal,.mul_equal,.ns_c,.ns_separator,.or_equal,.plus_equal,.sl,.sl_equal,.sr,.sr_equal,.xor_equal,.start_heredoc,.end_heredoc,.object_operator,.paamayim_nekudotayim{color:black}.abstract,.array,.array_cast,.as,.break,.case,.catch,.class,.clone,.continue,.declare,.default,.do,.echo,.else,.elseif,.empty.enddeclare,.endfor,.endforach,.endif,.endswitch,.endwhile,.eval,.exit,.extends,.final,.for,.foreach,.function,.global,.goto,.if,.implements,.include,.include_once,.instanceof,.interface,.isset,.list,.namespace,.new,.print,.private,.public,.protected,.require,.require_once,.return,.static,.switch,.throw,.try,.unset,.use,.var,.while{color:royalblue}.open_tag,.open_tag_with_echo,.close_tag{color:orange}.ini_section{color:black}.ini_key{color:royalblue}.ini_value{color:crimson}.xml_tag{color:dodgerblue}.xml_attr{color:blueviolet}.xml_data{color:red}.section{color:black}.directive{color:blue}.data{color:dimgray}
</style>
</head>
<body>
<h1>Internal Server Error</h1>
<p>mkdir(): Permission denied</p>
</body>
</html>
My folder is set to full permissions:

Related

problem with ajax or maybe with postmapping

So, i am trying to use ajax and it seems I am not able to run
searchRequest.open("POST", "/test?q=" + $("#q").val(), true);
from my jsp file.
<script>
//testView.jsp
function search() {
const searchRequest = new XMLHttpRequest();
searchRequest.open("POST", "/test?q=" + $("#q").val(), true);
alert("???")
searchRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf8");
alert("??")
searchRequest.onreadystatechange = () => {
if(searchRequest.readyState == 4 && searchRequest.status == 200) {
console.log("gwew", searchRequest.responseText);
const table = $("#ajaxTable")[0]; // dom 반환
table.innerHTML = "";
const object = JSON.parse(searchRequest.responseText);
alert(q)
....
this is my jsp file, and I have a testController.java like this.
#Controller
public class testController {
#GetMapping(value = "/test")
public String test(){
System.out.println("GET");
return "testView";
}
#PostMapping(value = "/test",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
#ResponseBody
public String testing(#RequestParam(required = false) String q) {
System.out.println("POST");
return q;
}
}
Not sure where I am getting wrong. Am I getting problem on #Postmapping?

My PDO class returns Error on Execution

I finished transitioning to PDO and am modifying my system according to fatal errors that pop up.
ERR: Call to a member function execute() on a non-object in /home/a1933806/public_html/globals/server-bin/php/core.php
LINE: 43
This is my setup with affected line in bold:
class netCore {
private $armor;
private $boot;
private $dbHost = "*****.*******.com";
private $dbNAME = "********";
private $dbPASS = "********";
private $dbUSR = "********";
private $err;
private $state;
public function __construct() {
$bootloadr = "mysql:host=".$this->dbHost.";dbname=".$this->dbNAME.";charset=UTF8";
$opt = array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
try {
$this->boot = new PDO($bootloadr, $this->dbUSR, $this->dbPASS, $opt);
} catch(PDOException $e) {
$this->err = "<b>Lebensborn® netCore™ Error:</b> An exception has been raised during Network-to-Database procedures.<br /><b>Message:</b> ".$e->getMessage().".";
}
}
public function bind($param, $value, $type = null) {
if(is_null($type)) {
switch(true) {
case is_int($value):
$type = PDO::PARAM_INT;
break;
case is_bool($value):
$type = PDO::PARAM_BOOL;
break;
case is_null($value):
$type = PDO::PARAM_NULL;
break;
default:
$type = PDO::PARAM_STR;
}
}
$this->state->bindValue($param, $value, $type);
}
public function exe() {
return $this->state->execute();
}
public function count() {
return $this->state->rowCount();
}
public function q($q) {
try {
$this->armor = $this->boot->prepare($q);
$this->state = $armor;
} catch(PDOException $e) {
$this->err = "<b>Lebensborn® netCore™ Error:</b> An exception has been raised during Network-to-Database procedures.<br /><b>Message:</b> ".$e->getMessage().".";
}
}
public function set() {
$this->exe();
return $this->state->fetchAll(PDO::FETCH_ASSOC);
}
public function single() {
$this->exe();
return $this->state->fetch(PDO::FETCH_ASSOC);
}
public function transBegin() {
return $this->boot->beginTransaction();
}
public function transCancel() {
return $this->boot->rollBack();
}
public function transEnd() {
return $this->boot->commit();
}
}

dynamic fetch data function

i have made simple database application in zend framework.in that i have made user class and defined different function for database interaction.this function are called from controller class..but i have to declare each time class object for calling the method of user class in each action.how can i declare user class object one time and use in all action method of controller.
here is my controller page
class UserController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
Zend_Session::start();
}
public function indexAction()
{
$title = Zend_Registry::get('title');
$this->view->assign('name', 'Wiwit');
$this->view->assign('title', $title);
}
public function logoutAction()
{
Zend_Session::destroy();
$this->redirect("/user/login");
}
public function registerAction()
{
$this->view->assign('title','Register');
$request = $this->getRequest();
$this->view->assign('action', $request->getBaseURL()."/user/register");
if($request->isPost())
{
$data = array('first_name' => $request->getParam('first_name'),
'last_name' => $request->getParam('last_name'),
'user_name' => $request->getParam('user_name'),
'password' => $request->getParam('password')
);
$user = new Application_Model_User();
$rows_affected=$user->user_insert($data);
$this->redirect("/user/login");
}
}
public function loginAction()
{
if(isset($_SESSION['username']))
{
$this->redirect("/user/home");
}
$this->view->assign('title','Register');
$request = $this->getRequest();
$this->view->assign('action', $request->getBaseURL()."/user/login");
if($request->getParam('msg'))
{
$this->view->msg='username or password is invalid';
}
if($request->isPost())
{
$data = array(
'user_name' => $request->getParam('user_name'),
'password' => $request->getParam('password')
);
$user = new Application_Model_User();
$result=$user->user_login($data);
if(empty($result)){
$this->redirect("/user/login/msg/login failed");
}
else{
$_SESSION['username']=$result->user_name;
$this->redirect("/user/home");
}
}
}
public function homeAction()
{
if(isset($_SESSION['username']))
{
$this->view->title='home';
$request = $this->getRequest();
$user = new Application_Model_User();
$result=$user->user_grid();
$this->view->rows=$result;
}
else
{
$this->redirect("/user/login");
}
}
public function editAction()
{
$request = $this->getRequest();
$id= $request->getParam("id");
$user = new Application_Model_User();
$result=$user->user_edit($id);
$this->view->assign('data',$result);
$this->view->action= $request->getBaseURL()."/user/update";
}
}
and here is my user class
<?php
class Application_Model_User extends Zend_Db_Table
{
public function user_insert($data)
{
global $DB;
$rows_affected = $DB->insert('user', $data);
return $rows_affected;
}
public function user_login($data)
{
$u_name=array_shift($data);
$pass=array_shift($data);
$select = $this->_db->select()
->from('user')
->where("user_name = ?",$u_name)
->where("password = ?",$pass);
$result = $this->getAdapter()->fetchRow($select);
return $result;
}
public function user_grid()
{
global $DB;
$sql = 'SELECT * FROM user';
$stmt = $DB->query($sql);
$result = $stmt->fetchall();
return $result;
}
public function user_edit($data)
{
$select = $this->_db->select()
->from('user')
->where("id = ?",$data);
$result = $this->getAdapter()->fetchRow($select);
$data = (array) $result;
return $data;
}
public function userupdate($data,$id)
{
global $DB;
$rows_affected =$DB->update('user', $data,'id = '.$id);
return $rows_affected;
}
public function userdelete($id)
{
global $DB;
$rows_affected =$DB->delete('user','id = '.$id);
return $rows_affected;
}
}
?>
You can create your user object in the init() method, and store it as a class variable.
public function init()
{
/* Initialize action controller here */
Zend_Session::start();
$this->user = new Application_Model_User();
}
Then it's available in any action method.
public function homeAction()
{
if(isset($_SESSION['username']))
{
$this->view->title='home';
$request = $this->getRequest();
$result = $this->user->user_grid(); // changed
$this->view->rows=$result;
}
else
{
$this->redirect("/user/login");
}
}

Fatal error: Call to a member function getPermissionKeyByHandle() on a non-object

Hello I get the following messages at my site www.csvc.nl
Fatal error: Call to a member function getPermissionKeyByHandle() on a non-object in /var/www/vhosts/csvc.nl/httpdocs/cms/updates/concrete5.6.0/concrete/core/models/permission/response.php on line 53
The PHP code is:
<?php
defined('C5_EXECUTE') or die("Access Denied.");
class Concrete5_Model_PermissionResponse {
protected $object;
protected $allowedPermissions = array();
protected $customClassObjects = array();
protected $category;
static $cache = array();
public function setPermissionObject($object) {
$this->object = $object;
}
public function getPermissionObject() {
return $this->object;
}
public function setPermissionCategoryObject($category) {
$this->category = $category;
}
public function testForErrors() { }
public static function getResponse($object) {
$r = PermissionCache::getResponse($object);
if (is_object($r)) {
return $r;
}
$category = PermissionKeyCategory::getByHandle(Loader::helper('text')- >uncamelcase(get_class($object)));
if (!is_object($category) && $object instanceof Page) {
$category = PermissionKeyCategory::getByHandle('page');
}
$txt = Loader::helper('text');
$c1 = get_class($object) . 'PermissionResponse';
if (!class_exists($c1)) {
$c1 = 'PagePermissionResponse';
}
$pr = new $c1();
$pr->setPermissionObject($object);
$pr->setPermissionCategoryObject($category);
PermissionCache::addResponse($object, $pr);
return $pr;
}
public function validate($permission, $args = array()) {
$u = new User();
if ($u->isSuperUser()) {
return true;
}
$pk = $this->category->getPermissionKeyByHandle($permission);
if (!$pk) {
print t('Unable to get permission key for %s', $permission);
exit;
}
$pk->setPermissionObject($this->object);
return call_user_func_array(array($pk, 'validate'), $args);
}
public function __call($f, $a) {
$permission = substr($f, 3);
$permission = Loader::helper('text')->uncamelcase($permission);
return $this->validate($permission, $a);
}
}
Does anybody knows what the problem is?
I had a similar issue on an incomplete 5.6.0 upgrade.
Concrete 5 has a core upgrade troubleshooting guide
For me, I just had to do this on my site: http://example.com/index.php/tools/required/upgrade and use the upgrade button.
FYI, this added entries to PermissionKeyCategories and other tables (which existed, but were empty).

Basic Html5 Socket issue

Just wondering if some can help me with the issue, below is my web socket Helloserver code and the client.htm code. After starting the Helloserver we run the client and notice that it does not connect to the server, will really appreciate if someone can help.
Here is the client.htm:
<!doctype html>
<html>
<head>
<title>Web Sockets: Connecting to the Server</title>
<link rel="Stylesheet" href="/global.css" type="text/css" />
</head>
<body>
<div id="container">
<h1>Connecting to Web Socket Server</h1>
<ul id="log"></ul>
</div>
</body>
<script src="../scripts/jquery-1.7.2.js" type="text/javascript"></script>
<script>
$(function () {
function logMsg(message) {
$("#log").append("<li>" + message + "</li>");
}
logMsg("Attempting to connect to socket server");
var server = null;
try {
server = new WebSocket("ws://localhost:8181/server");
server.addEventListener("message", messageHandler, false);
server.addEventListener("open", openHandler, false);
server.addEventListener("close", closeHandler, false);
}
catch (e) {
}
function openHandler(e) {
logMsg("Connection opened");
}
function closeHandler(e) {
logMsg("Connection closed");
}
function messageHandler(e) {
logMsg("Server says: " + e.data);
}
});
</script>
</html>
Here is the server code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SocketServer.Models;
using Nugget;
namespace SocketServer
{
class HelloServer : ISocketServer
{
private string _serverPath = string.Empty;
private WebSocketServer _server = null;
private string _input = string.Empty;
public string Input
{
set { this._input = value; }
}
public void Initialize(string serverPath, string originServerAndPort)
{
this._server = new WebSocketServer(8181, originServerAndPort, "ws://localhost:8181");
this._server.RegisterHandler<Socket>(serverPath);
Nugget.Log.Level = LogLevel.None;
}
public void Start()
{
this._server.Start();
}
public void Send()
{
this._server.SendToAll(this._input);
}
}
}
Here is the console code to start the server:
using System;
using Nugget;
namespace SocketServer
{
class Server
{
static void Main(string[] args)
{
ISocketServer server = null;
Console.WriteLine();
Console.WriteLine("Welcome to the socket server.");
Console.WriteLine();
Console.WriteLine("Which server type would you like to create?");
Console.WriteLine(" 1) Hello World Server");
Console.WriteLine(" 2) Stocks Server");
Console.WriteLine();
string input = Console.ReadLine();
if (input == "1")
{
server = new HelloServer();
server.Initialize("/server", "http://localhost:2709");
Console.WriteLine("");
Console.WriteLine("The Hello World Server is now available under ws://localhost:8181/server.");
Console.WriteLine("");
}
else if (input == "2")
{
server = new StockServer();
server.Initialize("/stocks", "http://localhost:2709");
Console.WriteLine("");
Console.WriteLine("The Stocks Server is now available under ws://localhost:8181/stocks.");
Console.WriteLine("");
}
else
{
Console.WriteLine("");
Console.WriteLine(string.Format("Sorry, {0} is not a valid option.", input));
Console.WriteLine("");
}
if (server != null)
{
server.Start();
input = string.Empty;
while (input != "exit")
{
server.Input = input;
server.Send();
input = Console.ReadLine();
}
}
Console.WriteLine("");
Console.WriteLine("Closing socket server.");
Console.WriteLine("");
}
}
}
The issue we are having is that after the client is run it gives this message and does not connect to the server:
Attempting to connect to socket server
Connection closed
Any help will be appreciated.
Make sure that websockets are enabled in the browser you use.
In the other hand you may want to revise this line in client.html
server = new WebSocket("ws://localhost:8181/server");
Is the "/server" part necessary ?