Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Phalcon\Logger\Adapter::commit() clear the queue #1748

Merged
merged 3 commits into from Jan 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
- Phalcon\Events:
- Added support for weak references (#663)
- Bug fix in Phalcon\Events\manager::attach() (#1331, #1337)
- Phalcon\Flash:
- Phalcon\Flash\Session::getMessage('key') returns now an empty array if the key is not found (#908, #920)
- Phalcon\Flash\Session::getMessages() incorrectly removed all messages (#1575)
- Implemented Phalcon\Flash\Session::isset() (#1342)
- Phalcon\Forms:
- Phalcon\Forms\Element\* classes now implement Phalcon\Form\ElementInterface
- Added support for HTML attributes to Phalcon\Forms\Form::label() (#1029)
Expand Down Expand Up @@ -160,6 +164,7 @@
- Added Phalcon\Logger\Adapter\File::getPath() (#1495, #1508)
- Phalcon\Logger optimizations (#1716)
- Phalcon\Logger\Adapter::setLogLevel() is honored by transactions (#1716)
- Phalcon\Logger\Adapter::commit() now clears the queue (#1742)
- Phalcon\Mvc:
- Phalcon\Mvc\Application::handle() now checks whether the class exists before include()'ing its file (#812, #818)
- Phalcon\Mvc\Model\Criteria::fromInput() now sets _modelName (#866, #873)
Expand Down Expand Up @@ -200,10 +205,6 @@
- Fixed handling of numeric namespaces/modules/controllers/actions (#1688)
- Added Phalcon\Mvc\View::exists() and Phalcon\Mvc\View(\Simple)::getRegisteredEngines() (#1707)
- Volt: fixed bug in email_filed() (#1723)
- Phalcon\Flash:
- Phalcon\Flash\Session::getMessage('key') returns now an empty array if the key is not found (#908, #920)
- Phalcon\Flash\Session::getMessages() incorrectly removed all messages (#1575)
- Implemented Phalcon\Flash\Session::isset() (#1342)
- Phalcon\Paginator:
- Phalcon\Paginator\Adapter\Model returns correct results even when page number is incorrect (#1654)
- Optimized Phalcon\Paginator\Adapter\QueryBuilder (#1632)
Expand Down
9 changes: 9 additions & 0 deletions ext/logger/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ PHP_METHOD(Phalcon_Logger_Adapter, commit){
phalcon_call_method(time, *message, "gettime");
phalcon_call_method_p3_noret(this_ptr, "loginternal", message_str, type, time);
}

if (Z_REFCOUNT_P(queue) == 1 || Z_ISREF_P(queue)) {
zend_hash_clean(Z_ARRVAL_P(queue));
}
else {
PHALCON_ALLOC_GHOST_ZVAL(queue);
array_init(queue);
phalcon_update_property_this(getThis(), SL("_queue"), queue TSRMLS_CC);
}
}

RETURN_THIS();
Expand Down
27 changes: 27 additions & 0 deletions ext/tests/issue-1742.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Phalcon\Logger\Adapter::commit() does not clear the queue - https://github.com/phalcon/cphalcon/issues/1742
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
class MyStreamAdapter extends \Phalcon\Logger\Adapter\Stream
{
public function getQueueSize()
{
return count($this->_queue);
}
}

$logger = new MyStreamAdapter("php://stdout");
$logger->begin();
$logger->log('info', \Phalcon\Logger::INFO);
$logger->log('critical', \Phalcon\Logger::CRITICAL);
echo $logger->getQueueSize(), PHP_EOL;
$logger->commit();
echo $logger->getQueueSize(), PHP_EOL;
?>
--EXPECTF--
2
[%s, %d %s %d %d:%d:%d %s][INFO] info
[%s, %d %s %d %d:%d:%d %s][CRITICAL] critical
0