I'm working on adding an additional column to an existing backend extension.
I'm determining the sells of the products to display their health of (roughly) the last 3 months.
If I implement this column the page takes upwards of a minute to be generated.
The code for the query I'm adding to the extension is:
$fromDate = date('Y-m-d H:i:s', strtotime('-90 days'));
$toDate = date('Y-m-d H:i:s', strtotime('-0 days'));
$collection->getSelect()->joinLeft(
array('order_items' => 'sales_flat_order_item'),
"`order_items`.`product_id` = `e`.`entity_id` AND
`order_items`.`created_at` BETWEEN '{$fromDate}' AND '{$toDate}'
AND `order_items`.`order_id` IN (SELECT entity_id FROM sales_flat_order
WHERE status = 'processing' OR status = 'complete' OR status = 'closed')
",
array('order_id', 'product_id')
);
$collection->getSelect()->columns('COUNT(order_items.order_id) AS stock_health');
$collection->getSelect()->group('e.entity_id');
The code for the column I'm adding is:
$stockManagerModel = Mage::getModel('stocklist/status');
$this->addColumn('stock_health', array(
'header' => 'Health', //Mage::helper('stocklist')->__('Health'),
'align' => 'right',
'filter' => false,
'width' => '60px',
'order_callback' => array($this, '_customSort'),
'renderer' => 'stocklist/adminhtml_widget_grid_column_renderer_health',
'index' => 'stock_health',
));
What is causing this extension to be so slow after this addition? What changes could/should be made? Is there a better way to implement this?
Just a bit doubt, are you checking your compilation process? Is it disabled or do you Run Compilation process once the module is enabled?
Related
Finishing of my elgg plugin has come to some issues, after fixing my last question I have encountered another. Apperently I am misusing or misunderstanding the use of the Created time lower and upper functions in Elgg
With the code below:
$monthSpan = (30 * 24 * 60 * 60);
$startTime = time() - $monthSpan;
$MemberDifference = elgg_get_entities_from_relationship(array(
'relationship' => 'member', //get Members
'relationship_guid' => $group->guid, //get individual guid for use
'inverse_relationship' => true,
'type' => 'user', //users are returned
'limit' => 20,
'joins' => array("JOIN {$db_prefix}users_entity u ON e.guid=u.guid"),
'order_by' => 'u.name ASC',
'relationship_created_time_lower' => $startTime, //the furthest back it will reach
'relationship_created_time_upper' => time(), //possibly unneeded, but ensures the closest date is today
'count' => true,
));
Using this function, I built it upon my way to get all of the members in the associated group, theoretically it should now grab any members that registered to that group within the last month. Unfortunately, it instead continues to grab every member in the group, regardless of the time they joined.
Does anyone have any information into where I have went wrong?
Turns out, my version of Elgg was too low, otherwise that entire block of code would work. Working Elgg 1.8, I needed to use the following code:
$MemberDifference = elgg_get_entities_from_relationship_count(array(
'relationship' => 'member',
'relationship_guid' => $Reports->guid,
'inverse_relationship' => true,
'type' => 'user',
'limit' => 20,
'count' => true,
'joins' => array("JOIN {$db_prefix}users_entity u ON e.guid=u.guid"),
'order_by' => 'u.name ASC',
'wheres' => array('r.time_created >=' . $startTime)
));
This works perfectly and brings about exactly what im looking for.
Omise PHP get all charges
ref : https://www.omise.co/charges-api
$charges = OmiseCharge::retrieve();
this code gives me 20 records which is okay.
$response = OmiseCharge::retrieve('',OMISE_PUBLIC_KEY,OMISE_SECRET_KEY);
this also gives me first 20 records.
but my requirement is fetch all charges with date params.
$param = array(
'from' => '2014-10-20 00:00:00',
'to' => '2014-09-25 00:00:00'
);
$response = OmiseCharge::retrieve($param);
this gives an error.
Fatal error: Uncaught exception 'OmiseNotFoundException' with message 'charge Array was not found'
what i am doing wrong.
currently Omise-PHP library doesn't support for passing array at the first parameter.
(As your solution) you have to pass it as string (including other filters, such as 'limit', 'offset').
$param = array(
'limit' => 40,
'offset' => 40,
'from' => '2011-10-20 00:00:00',
'to' => '2016-09-25 00:00:00'
);
$charges = OmiseCharge::retrieve('?'.http_build_query($param));
I don't know this library but after quick search some tips:
First of all (if you not already done this) read this doc about pagination.
I found that date has different format: iso8601 what means for ex 2014-10-20T00:00:00Z.
limit to 20 records you can change to 100, try to use pagination
BTW. Interesting API.
$param = array(
'from' => '2011-10-20 00:00:00',
'to' => '2016-09-25 00:00:00'
);
$response = OmiseCharge::retrieve('?'.http_build_query($param));
worked for me.
Good Morning. I am having trouble comparing a timestamp returned as a meta_key (returning as a string) to the current timestamp while running get_posts().
I am trying to get any posts with end_date_time set in the future and I am getting some weird behavior. I am using Advanced Custom Fields and Advanced Custom Fields: Date and Time Picker to set the time.
Here is my code:
$time = time();
$args = array(
'post_type' => 'webinars',
'posts_per_page' => -1,
'meta_key' => 'date',
'orderby' => array('meta_value_num' => 'ASC', 'title' => 'ASC'),
'meta_query' => array(
array(
'key' => 'end_date_time',
'value' => $time,
'compare' => '>='
),
),
);
$webinars = get_posts($args);
The query does not return any results if it is set like this. I know that there is a post with a future timestamp set as removing the meta_query shows it and I can get the saved time stamp. (It is saved as a string).
Is there an issue with comparing strings as numbers in a meta_query? Is there a way to convert end_date_time to an int before doing the comparison?
I have also tried converting time to a string before passing it into the $args, but it does not seem to make a difference.
Has anyone else run into this issue?
Update
I have modified the $time variable to use a past time like this:
$time = time()-43200;
After doing this, the query seems to be working fine. If I set end_date_time to the future it will show in the loop, if I set it to the past it is removed from the loop. It seems that there is some sort of time discrepancy that is causing this. Without the adjusted time, events that happened two hours from now would disappear, but after the adjustment they stay displayed. When they are several hours old they still disappear as needed.
Why would this work with the adjusted timestamp $time = time()-43200;, but not with $time = time();?
If you're using the native ACF's Date Time Picker, you should just add type DATETIME to your meta_query and be sure your value has the required format yyyy-mm-dd hh:mm:ss.
'meta_query' => array(
array(
'key' => 'end_date_time',
'value' => date('Y-m-d H:i:s', $time),
'compare' => '>=',
'type' => 'DATETIME'
),
),
Check Date Time Picker and WP's Meta Queries documentation.
I'm running into issues sending data to my DynamoDB. I have no idea what the issue is because it appears the program runs correctly, however I don't seem to have any data in my DB. I was able to create tables using Amazons tutorial, but when I follow this tutorial, I get a failed response if I try and put ALL the items, and a false success when it's only one item, as nothing is updated in the db.
Here's the code, I'm curious specifically if anyone knows a means to debug these kinds of issues.
<?php
// If necessary, reference the sdk.class.php file.
// For example, the following line assumes the sdk.class.php file is
// in an sdk sub-directory relative to this file
require_once('includes/backend.php');
// Instantiate the class
$dynamodb = new AmazonDynamoDB();
####################################################################
# Setup some local variables for dates
$one_day_ago = date('Y-m-d H:i:s', strtotime("-1 days"));
$seven_days_ago = date('Y-m-d H:i:s', strtotime("-7 days"));
$fourteen_days_ago = date('Y-m-d H:i:s', strtotime("-14 days"));
$twenty_one_days_ago = date('Y-m-d H:i:s', strtotime("-21 days"));
####################################################################
# Adding data to the table
echo PHP_EOL . PHP_EOL;
echo "# Adding data to the table..." . PHP_EOL;
// Set up batch requests
$queue = new CFBatchRequest();
$queue->use_credentials($dynamodb->credentials);
// Add items to the batch
$dynamodb->batch($queue)->put_item(array(
'TableName' => 'ProductCatalog',
'Item' => array(
'Id' => array( AmazonDynamoDB::TYPE_NUMBER => '101' ), // Hash Key
'Title' => array( AmazonDynamoDB::TYPE_STRING => 'Book 101 Title' ),
'ISBN' => array( AmazonDynamoDB::TYPE_STRING => '111-1111111111' ),
'Authors' => array( AmazonDynamoDB::TYPE_ARRAY_OF_STRINGS => array('Author1') ),
'Price' => array( AmazonDynamoDB::TYPE_NUMBER => '2' ),
'Dimensions' => array( AmazonDynamoDB::TYPE_STRING => '8.5 x 11.0 x 0.5' ),
'PageCount' => array( AmazonDynamoDB::TYPE_NUMBER => '500' ),
'InPublication' => array( AmazonDynamoDB::TYPE_NUMBER => '1' ),
'ProductCategory' => array( AmazonDynamoDB::TYPE_STRING => 'Book' )
)
));
echo "Item put in <b>Reply</b>" . "<br/>";
// Execute the batch of requests in parallel
$responses = $dynamodb->batch($queue)->send();
// Check for success...
if ($responses->areOK())
{
echo "The data has been added to the table." . PHP_EOL;
}
else
{
utdump($responses);
}
Thank you for your time
Try setting your region explicitly, e.g. for EU you need to call:
$myDynamoDbObject->set_region('dynamodb.eu-west-1.amazonaws.com');
It might also be that you have two tables in different regions, your application work with one of them and you trying to read (or track with web console) another one because of different default regions applied.
If you're tracking number of items in the table, keep in mind that it is not a real time figure, it is only updated every 6 hours or so. So the way use can ensure your item is indeed written by trying to read it back immediately after you receive the "OK" response for your put request.
Does anyone know if it is possible to set timezone in the log4php library configuration?
I did not see any information regarding this in the official docs, but log4j has this implemented.
Right now, I am relying on php's *date_default_timezone_set* function to do the trick, but I wanted to leave log4php to handle this on its own... I wonder if there is a to-do list for this or we are supposed to rely on the built-in function by ourselves.
Here is the code I have:
date_default_timezone_set("America/New_York");
require_once (dirname(__FILE__) . '/lib/log4php/Logger.php');
Logger::configure(
array(
'appenders' => array(
'default' => array(
'class' => 'LoggerAppenderRollingFile',
'layout' => array(
'class' => 'LoggerLayoutPattern',
'params' => array(
'conversionPattern' => '%d{Y-m-d H:i:s.u} [%t] %-5p - %m%n'
)
),
'params' => array(
'file' => '/var/log/myapp/myapp.' . date('Y-m-d') . '.log',
'maxFileSize' => '1MB',
'maxBackupIndex' => 10,
),
),
),
'rootLogger' => array(
'appenders' => array('default'),
),
)
);
$logger = Logger::getLogger('myapp');
for( $i=0; $i<5000; $i++ ) {
$logger->info("This is a test [${i}].");
}
In case this code serves someone else with similar issue.
Be safe,
A defined default timezone belongs to a fully working php application.
Apart from that, you are not very clear in stating what you expect log4php to do. The project has everything from mailing list to issue tracker - you are welcome to send your wishes.
I had a similar problem. You can log the date and time for UTC/GMT in the log4php by changing one line of code in the module.
Here is how I did. Go to the module and find the file LoggerPatternConverterDate.php.
cd log4php/pattern/
vim LoggerPatternConverterDate.php
Find the private function date($format, $utimestamp) (Line 84 for me) and change the line of code that returns.
This:
return date(preg_replace('`(?<!\\\\)u`', $ms, $format), $timestamp);
Becomes:
return gmdate(preg_replace('`(?<!\\\\)u`', $ms, $format), $timestamp);
Also, find the file: log4php/appenders/LoggerAppenderDailyFile.php and change the following line:
This:
return date($this->datePattern, $timestamp);
Becomes:
return gmdate($this->datePattern, $timestamp);
NOTE: The only thing changed is the function used to format the date string. date() depends on timezone that you set using date_default_timezone_set whereas gmdate() formats the date and time in UTC/GMT irrespective of default timezone.