Google Calendar API Call to Non-Object [duplicate] - google-calendar-api

This question already has answers here:
Call to a member function on a non-object [duplicate]
(8 answers)
Closed 10 years ago.
I'm getting an error at the setSummary line in my code below. I included Google's example code. Is this a bug or is there something wrong with my code?
$event = new Event();
$task = $tasks[0];
if (!empty($refreshToken) && !empty($calendarId)) {
$client->refreshToken($refreshToken);
if (!empty($task[145])) {
$event = $calendarServer->events->get($calendarId, $task[145]);
}
$event->setSummary('test string');
Example Google Code from https://developers.google.com/google-apps/calendar/v3/reference/events/update
$event = $service->events->get('primary', 'eventId');
$event->setSummary('Appointment at Somewhere');
$updatedEvent = $service->events->update('primary', $event->getId(), $event);
echo $updatedEvent->getUpdated();
My script is breaking at the line setSummary with error:
( ! ) Fatal error: Call to a member function setSummary() on a non-object in /vagrant/public/gcalendar/sync.php on line 47

I updated to the newest version of the php sdk, and figured out that I was not properly creating the new "event object" if the event already exists. The following is what I'm currently using.
if (!empty($eventIdString)) {
$event = new Google_Event($calendarServer->events->get($calendarId, $eventIdString));
}
else {
$event = new Google_Event();
}

Related

Magento 2 - How to get the currentStoreId() from external App?

I asked this question in Magento Stack Exchange but did not get any comment/answer from anyone. So I deleted the question over there and asking the same question in SO.
So, I have an external App which logs an admin user into the admin panel. Barebone structure is as follows:
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
class TestApp extends \Magento\Framework\App\Http implements \Magento\Framework\AppInterface {
protected $_resource = null;
protected $storeManager = null;
public function __construct(
//ActionContext $context,
\Magento\Framework\App\ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Customer\Model\CustomerFactory $customerFactory
// \Magento\Catalog\Model\Session $catalogSession,
// \Magento\Framework\App\State $state
) {
$this->_resource = $resource;
$this->storeManager = $storeManager;
}
public function launch() {
$currentStoreID = $this->storeManager->getStore()->getStoreId();
}
}
$bootstrap = Bootstrap::create(BP, $_SERVER);
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** #var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('TestApp');
$bootstrap->run($app);
I have stripped off the actual login part because this is out of the context of this question.
If I call $this->storeManager->getStore()->getStoreId();, it returns the default store ID, which is not what I want. This application resides under a sub-store (not sure if that's the correct term to use) and I want the current store ID, not the default one.
Following up, I found this closed issue where the user was told to use \Magento\Store\Model\StoreResolver::getCurrentStoreId. $this->storeManager does have storeResolver inside but that's a protected property, thus inaccessible.
My question is, how do I get the current store ID and not the default one?

Silverstripe 3.1 - BetterButtons Custom Action in DataExtension

Is there a way to add a custom button to the Member Object with Unclecheese BetterButtons? I'm extending the Member Object with a DataExtension where I want to create a BetterButtons Custom Action.
That's my code and the error I receive
private static $better_buttons_actions = array(
'createAccountPdf'
);
public function getBetterButtonsActions(){
$fields = parent::getBetterButtonsActions();
if( $this->owner->Accounts()->Count() > 0 ){
$fields->push(BetterButtonCustomAction::create('createAccountPdf', 'Datenblatt erstellen')->setSuccessMessage('PDF Datenblatt mit Zugangsdaten wurde erstellt.'));
}
return $fields;
}
Error:
Fatal error: Call to undefined method DataObject::getBetterButtonsActions() in /_website/_dev/mysite/code/Extensions/ClientMemberExtension.php on line 128
Instead of parent::getBetterButtonsActions() I also tried it with $this->owner, Member::, DataObject::
This sounds logical cause the parent of your extension doesn't have a method called "getBetterButtonActions".
From the code in BetterButtonDataObject i see there is already a hook to update ButtonActions in a DataExtension.
try:
public function updateBetterButtonsActions(&$actions) {
if( $this->owner->Accounts()->Count() > 0 ){
$actions->push(BetterButtonCustomAction::create('createAccountPdf', 'Datenblatt erstellen')->setSuccessMessage('PDF Datenblatt mit Zugangsdaten wurde erstellt.'));
}
}

Call to a member function get_items() on a non object in woocommerce

I am making a plugin that works in collaboration with woocommerce WordPress plugin. I am getting an error when trying to get items for an order:
"Fatal error: Call to a member function get_items() on a non-object in /home/telesqua/public_html/mehtab/wp-content/plugins/order-grabber/order-grabber.php on line 283"
and this is what is on line 283 and around it:
function post_order()
{
if(isset($order_id))
{
$order = new WC_Order($order_id);
}
$items = $order->get_items();
$number_of_items_in_this_order = $order->get_item_count();
Can anyone help me point out the problem? I can provide the source file if needed.
this is because it an add_action has to be executed after using the above code
add_action('init', 'post_order');

Class not found when trying to index documents using Solr with Symfony2

I am very new to Solr and I am probably missing something simple however, having followed Xavier Briand's presentation I have set up Symfony2, Solarium and Nelmio\SolariumBundle.
"nelmio/solarium-bundle": "2.0.*#dev",
"solarium/solarium": "3.0.*"
Having implemented a toSolrDocument method for my doctrine php object.
public function toSolrDocument(\Solarium_Document_ReadWrite $doc)
{
$doc->id = $this->getId();
$doc->description = $this->getTitle();
$doc->path = "path";
return $doc;
}
I am faced with the following error.
Catchable Fatal Error: Argument 1 passed to ::toSolrDocument() must be an instance of Solarium_Document_ReadWrite, instance of Solarium\QueryType\Update\Query\Document given, called in Controller.php
The controller calling this toSolrDocument method has the following function
public function indexItems(){
$client = $this->get('solarium.client');
// get an update query instance
$update = $client->createUpdate();
// create documents
$documents = array();
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('<Bundle>:<Object>');
$items = $repo->findAll();
foreach ($items as $item) {
$documents[] = $item->toSolrDocument($update->createDocument());
}
// add the documents and a commit command to the update query
$update->addDocuments($documents);
$update->addCommit();
// this executes the query and returns the result
$result = $client->update($update);
}
Most of this method again comes directly from Xavier's presentation and it is clear to see that the method $update->createDocument() does not return the correct type. In fact it returns an instance of the my php object. Does anyone know where I am going wrong here? Another thing that might be of help is that even when I try to pass a Solarium Document directly I get an exception.
foreach ($items as $item) {
$rw_item = new \Solarium_Document_ReadWrite();
$documents[] = $item->toSolrDocument($rw_item);
}
The exception is
FatalErrorException: Error: Class 'Solarium_Document_ReadWrite' not found in
I can't seem to find this class in any of the bundles and I am wondering if my setup might be causing the issues. Any help would be very much appreciated.
One additional point to note is that when I am running the solr jar I see the query requests come in from my symfony2 page it is only this indexing action that I can not work out so the config may be alright and I am miss understanding the use of the bundle.
You just need to use the correct class for the argument.
use Solarium\QueryType\Select\Result\AbstractDocument;
...
public function toSolrDocument(AbstractDocument $doc)
{
You could also not type hint it:
public function toSolrDocument($doc)
{

Symfony2 repository query not working

I am developing an application using Symfony2 and DQL for building some queries in the repositories. I have the next code in the controller:
$emGalPak = $this->getDoctrine()->getEntityManager();
$OsatugabeKop = $emGalPak->getRepository('AnotatzaileaAnotatzaileaBundle:GalderaPaketea')
->getOsatugabeKop();
and this is the query I built in the repository corresponding to the entity mentioned above:
<?php
namespace Anotatzailea\AnotatzaileaBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* GalderaPaketeaRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class GalderaPaketeaRepository extends EntityRepository
{
public function getOsatugabeKop()
{
$qb = $this->createQueryBuilder('c')
->select('c')
->where('c.Osatua = 0')
$Emaitza = $qb->getQuery()->getResult();
return sizeof($Emaitza);
}
}
When running the code it shows the next error:
Parse error: syntax error, unexpected T_VARIABLE in /var/www/Symfony/src/Anotatzailea/AnotatzaileaBundle/Repository/GalderaPaketeaRepository.php on line 20
Any idea on how I can solve this error?
This has nothing to do with your query not working.
When you see a "Parse error" that means your PHP code itself is improperly formatted and the PHP engine cannot even parse it, let alone run it.
In this particular case, you're missing a semicolon at the end of your expression creating the query builder.
public function getOsatugabeKop()
{
$qb = $this->createQueryBuilder('c')
->select('c')
->where('c.Osatua = 0'); // <--- right there
$Emaitza = $qb->getQuery()->getResult();
return sizeof($Emaitza);
}
When you get the unexpected T_VARIABLE error that's almost always because you omitted a semicolon and the parser encountered a variable before it thought it should. It's easier to see the mistake if you take out the whitespace.
// Bad Code, two lines
$now = time()
$one = 1;
// Bad Code, one line
$now = time()$one = 1;
// ----------^ Pretty obvious now that a semicolon is missing
// And that a variable was encountered unexpectedly
Cheers
Semicolon missing after where line.

Resources