File handle not remaining valid in a property; CakePhp 2x

2014-07-09 Thread dreamingmind
 I'm using the File Utility to read a file. I need to work with the file in 
some other methods and want to prevent access to it during the process, so 
I'm trying to get an exclusive lock on the file.

That seems to work fine... but while I have the file open and 'locked' I 
can make another File object for it and open and lock that also. That would 
be bad!

What I've found so far, if I examine the handle property of the file object 
while I'm in the readProcessed() method (shown below) I get something like:

*resource*(*92*, *stream*)

If I examine that same property from the code that instantiates 
NotificationFileHandler and calls readProcessed(), I see something like:

*resource*(*92*, *Unknown*) 


This looks like some sort of scope problem, but I can't really understand why 
that should be or what I'm doing wrong.

// the method in question.

class NotificationFileHandler {

* Read the processed file
 * 
 * This method locks the processed file while reading and handling
 * It includes a 20 second wait routine to attempt to process the file
 * if it is already in use
 * 
 * @return mixed FALSE if fail, the data in array form is successful
 */
public function readProcessed() {
$this->processedFile = new File($this->processedPath);
$this->processedFile->open();
$t = time()+20;
while ($t > time() && $this->processedFile->lock != LOCK_EX){
if(flock($this->processedFile->handle, LOCK_EX)){
$this->processedFile->lock = LOCK_EX;
}
}
if($this->processedFile->lock != LOCK_EX){
return FALSE;
}
return $this->processedFile->read();
}

}

// the calling code snippet
$note = new NotificationFileHandler();
$note->readProcessed();

   // this should return false but succeeds instead
$intruder = new NotificationFileHandler();
$intruder->readProcessed();


 Don

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: paths in cake environment being mangled

2014-07-09 Thread McScreech
OK, scratch the blank page error. I noticed an issue with my httpd.conf 
file where the "c:/www/pub" directory directive had the option 
'AllowOverride None'. I changed it to 'AllowOverride All' and am displaying 
the page with a variety of errors - at least I now have something visible 
to work with, eh? ;-)

BTW, the paths are still mangled as described in my original post.

On Wednesday, 9 July 2014 13:36:14 UTC-4, McScreech wrote:
>
> P.S. When I try to access the login page it returns a blank page with the 
> following message regardless of changes to any path variable:
> 'Not Found 
>
> The requested URL /promats/users/login was not found on this server.'
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: paths in cake environment being mangled

2014-07-09 Thread McScreech
P.S. When I try to access the login page it returns a blank page with the 
following message regardless of changes to any path variable:
'Not Found 

The requested URL /promats/users/login was not found on this server.'

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


paths in cake environment being mangled

2014-07-09 Thread McScreech
Hi all,

Can anyone explain this behaviour?

This setup worked for me prior to upgrading my pc from XP to Win7. I am now 
assuming that I have rebuilt my folder structure differently from the 
original setup with some detail missing/changed that has become invisible 
to me. However, the mangling of the path is the mystery part for me.

In brief (more details below), when i name the cake folder as follows the 
cake environment returns the following:
c:\www\apps\serv\cake\235is mangled to ->c:\www\apps\serv\cake5
c:\www\apps\serv\cake\2.3.5is mangled to ->c:\www\apps\serv\cake.3.5
c:\www\apps\serv\cake\v235is unchanged  ->
c:\www\apps\serv\cake\v235.

Many thanx, DaveT.


Here's my environment:
Server Software Apache/2.4.7 (Win32)
(with rewrite module enabled and correctly displayed by phpinfo)
Document Root c:/www/pub
Php Version 5.5.10
CAKE_VERSION 2.3.5
Path 
c:\WINDOWS\system32;c:\WINDOWS\System32\Wbem;c:\WINDOWS\System32\WindowsPowerShell\v1.0\;c:\WINDOWS;c:\www\apps\serv\php;c:\www\apps\serv\mysql\bin


Here's my file/folder structure:
c:\www
+---apps
|   \---serv
|   +---apache
|   +---cake
|   |   +---134
. . . 
|   |   +---235
|   |   +---245
|   |   \---_apps
|   |   +---GPD
|   |   +---GPDdev
|   |   +---promats
|   |   +---promatsdev
|   |   \---_Templates
|   |   +---134_default
|   |   +---134_skel
. . . 
|   |   +---234_skel
|   |   \---234_skel_dave
|   +---mysql
|   +---php
|   \---pma
+---priv
|   +---data
|   |   +---gpd
|   |   +---gpddev
|   |   +---promats
|   |   +---promatsdev
|   |   \---_config
|   \---share
+---pub
|   +---GPD(same structure as c:\www\pub\promats)
|   +---GPDdev(same structure as c:\www\pub\promats)
|   +---promats
|   |   +---css
|   |   +---files
|   |   +---img
|   |   \---js
|   |   \---jquery
|   +---promatsdev(same structure as c:\www\pub\promats)
|   \---_files
\---tmp


Here's my c:\www\pub\promats\index.php:
Only variables I've ever changed here are 'ROOT', 'APP_DIR', and 
'CAKE_CORE_INCLUDE_PATH'.

 ROOT is: ' . dirname(dirname(dirname(__FILE__))) . DS . 
'apps'. DS . 'serv'. DS . 'cake'. DS . '_apps');
//as defined by cake for original setup
//define('ROOT', dirname(dirname(dirname(__FILE__;
}

if (!defined('APP_DIR')) {
//as defined by me
define('APP_DIR', basename(dirname(__FILE__)));
echo (' APP_DIR is: ' . basename(dirname(__FILE__)));
//as defined by cake for original setup
//define('APP_DIR', basename(dirname(dirname(__FILE__;
}

//as defined by me
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))) . DS . 
'apps' . DS . 'serv' . DS . 'cake' . DS . '235' . DS . 'lib');
echo (' CAKE_CORE_INCLUDE_PATH is: ' . 
dirname(dirname(dirname(__FILE__))) . DS . 'apps' . DS . 'serv' . DS . 
'cake' . DS . '235' . DS . 'lib');

if (!defined('WEBROOT_DIR')) {
define('WEBROOT_DIR', basename(dirname(__FILE__)));
echo (' WEBROOT_DIR is: ' . basename(dirname(__FILE__)));
}
if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS);
echo (' WWW_ROOT is: ' . dirname(__FILE__));
}

// for built-in server
if (php_sapi_name() === 'cli-server') {
if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . 
$_SERVER['REQUEST_URI'])) {
return false;
}
$_SERVER['PHP_SELF'] = '/' . basename(__FILE__);
}

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) {
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . 
ini_get('include_path'));
}
if (!include ('Cake' . DS . 'bootstrap.php')) {
$failed = true;
}
} else {
if (!include (CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 
'bootstrap.php')) {
$failed = true;
}
}

// DJT: 3 lines for debugging routing
echo (' include_path is: ' . ROOT . DS . 'lib' . PATH_SEPARATOR . 
ini_get('include_path'));
echo (' CAKE_CORE_INCLUDE_PATH is: ' . CAKE_CORE_INCLUDE_PATH);
echo (' _');

if (!empty($failed)) {
trigger_error("CakePHP core could not be found. Check the value of 
CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the 
directory containing your " . DS . "cake core directory and your " . DS . 
"vendors root directory.", E_USER_ERROR);
}

App::uses('Dispatcher', 'Routing');

$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(
new CakeRequest(),
new CakeResponse()
);


Output from echo statements in c:\www\pub\promats\index.php:
(when cake folder is: 'c:\www\apps\serv\cake\235')
ROOT is:c:\www\apps\serv\cake\_apps
APP_DIR is:promats
CAKE_CORE_INCLUDE_PATH is:c:\www\apps\serv\cake\235\lib

(if i rename the cake folder to 'c:\www\apps\serv\cake\2.3.5' t

Re: Map checkboxes to bitmask

2014-07-09 Thread goku mai
Hello Boyan,

I am having same problem. What approach did you follow? 


Thanks



On Sunday, February 26, 2012 4:29:45 AM UTC-8, Boyan Penev wrote:
>
> Hello,
>
> I would like to accomplish the following: out of 2 checkboxes, if only the 
> first one is clicked, the value would be 10, if only the second one- 01, if 
> both - 11. I tried giving the checkboxes the same name(array) attribute and 
> different values, like:
> $this->Form->input('example', array('type' => 'checkbox', 'name' => 
> 'checked[]', 'value' => 1)
> and i get an indexed array over which i need to iterate in the controller.
> Does anyone have an idea, how could i map the values directly in the view, 
> in order for the controller to receive the final result?
>
> Thanks,
>
> Boyan
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: CakePHP Login redirect

2014-07-09 Thread Gagik Navasardyan
OK, I think this is the most suitable workaround for this case.

Thank you very much.

On Wednesday, July 9, 2014 4:01:37 AM UTC+10, bugoy wrote:
>
> Good point, though you can set the proper redirect in the function login() 
> in UserController, what is destroyed in logout for Session is Auth. You may 
> set a separate Session or Cookie for last logged user and check if same 
> with the current user the redirect Auth->redirect else redirect anywhere 
> else. 
>
>
> On Sat, Jul 5, 2014 at 10:31 PM, Gagik Navasardyan  > wrote:
>
>> Yes I'm sure that the Auth->logout action is being called, and the old 
>> session is certainly being destroyed too, before the new session is created.
>>
>> - I tried to rewrite the 'Auth.redirect' property before the Auth->logout 
>> action call, it have no effect because session is being destroyed. 
>> - I tried to rewrite that property after the Auth->logout call, of course 
>> it have no effect either, because as I understand after  the Auth->logout 
>> call the script terminates (by calling return).
>>
>> I made a little research and found the following code in > CakePHP>/lib/Cake/Controller/Component/AuthComponent.php (protected 
>> function _unauthenticated)
>>
>>
>> if ($this->_isLoginAction($controller)) { 
>> if (empty($controller->request->data)) { 
>> if (!$this->Session->check('Auth.redirect') && 
>> env('HTTP_REFERER')) { 
>> $this->Session->write('Auth.redirect', 
>> $controller->referer(null, true)); 
>> } 
>> } 
>> return true; 
>> }
>>
>> It seems to me that this code is responsible for users login, as we can 
>> understand from code:
>> - if user doesn't have the 'Auth.redirect' property set, means this is a 
>> new(not logged in) user who needs to login in order to view restricted 
>> content(for example after search) or user whom session is expired, then 
>> CakePHP redirects the user on the page on which he was before. And this is 
>> really a good idea.
>>
>> But as I understand this is creating my problem, because after the 
>> Auth->logout action call  Session is being destroyed, means there is no 
>> 'Auth.redirect' property, so CakePHP setting the 'Auth.redirect' from HTTP 
>> referer, and as I said this is good if user is coming from any place and 
>> needs to login(again for example from search), or user session is expired, 
>> but if user clicks the logout link and logs out he doesn't expect that 
>> after loging-in again he will return on the page on which he was before, he 
>> must be redirected not to the HTTP referer page, but the 'loginRedirect' 
>> page.
>>
>>  
>>
>> On Tuesday, 1 July 2014 13:14:48 UTC+10, Jeremy Burns wrote:
>>
>>> Are you certain the Auth->logout action is being called? Is the session 
>>> clear (destroyed) after logout?
>>>
>>> On 28 Jun 2014, at 12:54, Gagik Navasardyan  wrote:
>>>
>>> Hi everyone.
>>>
>>> I have one question. 
>>>
>>> I'm working on an application which is working in local network and 
>>> acting as POS(Point of Sale). As you understand it's based on CakePHP 
>>> framework.
>>> Now I'm encountering a strange behaviour, and I don't know is it a bug 
>>> or not, so I've decided to ask you a question here.
>>>
>>> - I'm using CakePHP 2.4.2 and the built-in AuthComponent for 
>>> authentication
>>>
>>> - *The thing is,* after user logs out and another user logs in (using 
>>> the same computer and browser), he is being redirected to the page on which 
>>> the previous user was when logged out. Instead of being redirected to the 
>>> URL defined in 'loginRedirect'
>>>
>>> - In this application I'm using role based user permissions system, and 
>>> the most of time system throwing permission error, because newly logged in 
>>> user doesn't have permission to view the page on which previous user was 
>>> when logged out.
>>>
>>> This behaviour is very strange to me, because as I know the logout 
>>> function is destroying session, but it seems keeping the last visited URL 
>>> of the previous user in the 'Auth.redirect' property in the new session.
>>> This seems a little bit strange to me, because I'm expecting this kind 
>>> of redirect in a few cases like:
>>> - If user session expired and user have to login again.
>>> - user trying to access to a page which is requiring authentication.  
>>>
>>> I analised the code and clearly the problem is in the framework core, 
>>> and there is no way to rewrite the 'Auth.redirect' property either before 
>>> or after the 'logout' function call (in any case the session being 
>>> destroyed and as I understand CakePHP taking and writing the last visited 
>>> page URL to the new session from HTTP REFERER).
>>>
>>>
>>> So question:
>>> Is this a Normal behaviour, and there are some reason why this must be 
>>> this way, or this is a bug?
>>>
>>> -- 
>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>> Find us on Twitter http://twitter.com/CakePHP
>>>
>>> --- 
>>