I am new to Extbase. There are two xml files that I want to access. One is abc.dll?type=xml from which I select the ID and then use this Id to fetch the values of other XML file(xyzzy.dll?type=xml and save all the data to the db. I want to create a task in Extbase and run it from command line.
Below is my code:
ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'TYPO3\Example\Command\XMLFetcherCommandController';
XMLFetcherCommandController:
namespace TYPO3\Example\Command;
class XMLFetcherCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController{
/**
* xmlload
*
* #return void
*/
public function findCommand(){
$path="http://abc.dll?type=room&content=xml";
$readXML=file_get_contents($path);
$xml = simplexml_load_string($readXML, "SimpleXMLElement",LIBXML_NOCDATA); $objectManager=\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$classesRepository = $objectManager->get('TYPO3\\Example\\Domain\\Repository\\ClassesRepository');
$json=json_encode($xml);
$xmlArray=json_decode($json,true);
$serialized_array = serialize($xmlArray);
$unserialized_array = unserialize($serialized_array);
$rooms = $unserialized_array['Rooms']['Room'];
foreach($rooms as $room){
$fetchXML= \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\Example\\Domain\\Model\\Classes');
$fetchXML->setRoomKey($room['Key']);
$fetchXML->setRoomID($room['ID']);
$classesRepository->add($fetchXML);
$newpaths[]='http:/xyz.dll?content=xml&type=room&id='.$room['ID'];
foreach($newpaths as $newpath){
$readLessons=file_get_contents($newpath);
$xmlLessons= simplexml_load_string($readLessons, "SimpleXMLElement",LIBXML_NOCDATA);
$objectManager=\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$classesRepository = $objectManager->get('Example\\Example\\Domain\\Repository\\ClassesRepository');
$json=json_encode($xml);
$xmlArray=json_decode($json,true);
$serialized_array = serialize($xmlArray);
$unserialized_array = unserialize($serialized_array);
$Lessons = $unserialized_array['Lesson'];
foreach ($Lessons as $Lesson) {
$fetchXMLNew= \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Example\\Example\\Domain\\Model\\Classes');
$date=date('Ymd',strtotime($Lesson['Date']));
$start=date('Hi',strtotime($Lesson['Start']));
$finish=date('Hi',strtotime($Lesson['Finish']));
$startdatetime=date('YmdHi',strtotime("$date$start"));
$finishdatetime=date('YmdHi',strtotime("$date$finish"));
$fetchXMLNew->setStartdatetime($startdatetime);
$fetchXMLNew->setEnddatetime($finishdatetime);
$classesRepository->add($fetchXML);
}
}
}
$classesRepository->persistAll();
}
}
}
?>
When I run- php cli_dispatch.phpsh extbase help - from cmd, I could not see my command controller which means it is not registered properly. Could you suggest if this is the right way to do it? At First, I created a Service and tried to call it, but since there was a lot of data it was taking a lot of time.
Maybe it does not work, becouse your class can not be loaded with autoloader?
If a class is not available, it will not be registerd.
(#see CommandManager->getAvailableCommands !class_exists($className)).
I think you need to escape the back slashes (=> Double Slashes)
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][]
= 'TYPO3\\Example\\Command\\XMLFetcherCommandController';
If this not work, you can also check the Namespace of your class. Why does it start with "TYPO3"?
If this also not work, you can try load your class hardcoded with require_once in AdditionalConfiguration.php to figure out whats wrong
Related
I am trying to do validation in symfony by using variables as shown below
$call= 'Assert\\'.$k2;
//echo $k2.'-'.$item;
echo $call;
//exit;
$arrayConstraint = new $call($item);
//$arrayConstraint = new Assert\NotBlank(null);
$errors = $this->get('validator')->validate(
$arr_item,
$arrayConstraint
);
This code gives error:
Attempted to load class "NotBlank" from namespace "Assert".
Did you forget a "use" statement for "Symfony\Component\Validator\Constraints\NotBlank"?
Whereas I am using the proper namespace(im including the class on top).
Whenevr i uncomment this line
$arrayConstraint = new Assert\NotBlank(null);
and comment this
//$arrayConstraint = new $call($item);
it works perfectly fine.
I guess this has something to do with calling classes using variables. Any ideas for a workaround?
Any help will be deeply appreciated
Finally I did it, by adding the whole path(namespace) to the variable.
$call= "Symfony\\Component\\Validator\\Constraints\\".$k2;
This is working now.
I have a Guidewire Gunit for a transformer in gosu which queries the system table to get a description for a result code which is working fine when run on the server but Gunit fails for the same.
I have tried the annotation #ServerTest for Gunit but that is failing as well.
The same code works fine in Gosu scratchpad.
PFA the code snippet as follows:
var resultCodes = Query.make(SystemTable).select().where(\elt -> elt.ResultCode == "AS01")
var description = ""
if(resultCodes != null && !resultCodes.isEmpty())
{
description = resultCodes.get(0).getFullDescription()
}
I'm getting the exception as follows :
java.lang.IllegalStateException: TableMetadataFactory cannot be used before it is started
Thanks,
Deepti
(Suggestion : )If your requirement is just to query based on some values.
Better dont use that .where() condition.
This is like SELECT * FROM <TABLE> and after getting all the data you are picking out your required result.
The best and the actual way is to use like
Query.make(TABLE_NAME).compare(TABLE_NAME#FIELD_NAME,Relop.Equals,"value_to_compare").select();
Query will be like
SELECT * FROM <TABLE_NAME> WHERE FIELD_NAME = FIELD_VALUE_TO_COMPARE;
While running Gunits, GW uses Shadow tables which will be basically empty.
Here if you are using OOTB entities, You can use Builder classes
or if you need to use some custom entities, use bundles to insert data first.
After inserting data into SystemTable (either using builder classes or bundles) run the below code.
var resultCodes = Query.make(SystemTable).compare(SystemTable#ResultCode ,Relop.Equals,"AS01").select()
foreach(result in resultCodes){
description = result.FullDescription
print("Output : "+description);
}
This happens when your RunLevel is set too low. Run levels below "NO_DAEMONS" will not load system tables. The default should be "NO_DAEMONS" so if you have an annotation on your test like this:
#RunLevel(gw.api.system.server.Runlevel.NONE)
either remove it or increase the level.
You can refactor your code like this:
uses gw.testharness.RunLevel
uses gw.api.database.Query
uses org.mockito.Mockito
uses gw.api.database.IQueryBeanResult
#RunLevel(NONE)
class StackOverflowTest {
function testDoQuery() {
var rs = Mockito.mock(IQueryBeanResult<SystemTable>)
var query = Mockito.mock(Query<SystemTable>)
Mockito.when(query.select()).thenReturn(rs)
var stackOverflow = Mockito.spy(new StackOverflow())
Mockito.doReturn(query).when(stackOverflow).getSystemTableQuery()
stackOverflow.doQuery()
Mockito.verify(stackOverflow, Mockito.times(1)).getSystemTableQuery()
Mockito.verify(query, Mockito.times(1)).select()
Mockito.verify(rs, Mockito.times(1)).iterator()
}
class StackOverflow {
function doQuery() {
var resultCodes = getSystemTableQuery().select().where(\elt -> elt.ResultCode == "AS01")
}
protected function getSystemTableQuery(): Query<SystemTable> {
return Query.make(SystemTable)
}
}
}
I spent a long time to work out how to do the following using Google Calendar using API V3 in PHP
insert a new event
read all existing events
delete each existing event
However I would still like to know how to clear an entire Google Calendar to make my code faster, as the read & delete method is a little slow.
I've been trying to work out how to use the supplied Google function "clear" for this, and the documentation supplied by Google simply shows that I should be able to use the following command to achieve this:
$service->calendars->clear('primary');
Also within the Google Code there is a comment relating to the "calendars" collection of methods (where the clear function exists):
Typical usage is:
<code>
$calendarService = new Google_Service_Calendar(...);
$calendars = $calendarService->calendars;
</code>
So I've put this together with the preceding authentication code. I am sure the authentication is working OK as I've used that elsewhere, but the clear code is obviously wrong as I get error message:
Notice: Undefined variable: service in C:\wamp\www\googleapi\clear\index.php on line 39
I've tried using 'primary' as well as the main owner, and I've tried making the calendar private and public but to no avail.
Anyone who has got the clear method to work, please point me in the right direction.
This is the code I'm running so far:
<?php
session_start();
require_once '../google-api-php-client-master/autoload.php';
//Google credentials
$client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com';
$service_account_name = 'xxxxxxxxxxxxxxxxxxxxxx#developer.gserviceaccount.com';
$key_file_location = '../google-api-php-client-master/API Project-xxxxxxx.p12';
if (!strlen($service_account_name) || !strlen($key_file_location))
echo missingServiceAccountDetailsWarning();
$client = new Google_Client();
$client->setApplicationName("Whatever the name of your app is");
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/calendar'),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
try {
$client->getAuth()->refreshTokenWithAssertion($cred);
} catch (Exception $e) {
var_dump($e->getMessage());
}
}
$_SESSION['service_token'] = $client->getAccessToken();
/* ------------------------- We are now properly authenticated ------------------- */
$calendarService = new Google_Service_Calendar($client);
$calendars = $calendarService->calendars;
$service->calendars->clear('primary');
?>
Just use your service calendar instance.
$service = new Google_Service_Calendar($client);
$calendar = $service->calendars->clear('primary');
I googled but didn't find a post for Flex mobile..
All I want for now is display an user agreement popup from TabbedViewNavigatorApplication when the user uses the app for the first time
var agreementView: UserAgreement = new UserAgreement();
PopUpManager.addPopUp(agreementView, this,true);
PopUpManager.centerPopUp(agreementView);
but maybe more later.
Please help..
What i did in my desktop air app;
I guess this will work at a mobile app also.
Make sure you have write access;
open yourproject-app.mxml scroll down to the end of the document. In the section, uncomment the following permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Now you can create files like for example an sqlite database.
At the applicationcomplete call the function checkFirstRun:
// functions to check if the application is run for the first time (also after updates)
// so important structural changes can be made here.
public var file:File;
public var currentVersion:Number;
private function checkFirstRun():void
{
//get the current application version.
currentVersion=getApplicationVersion();
//get versionfile
file = File.applicationStorageDirectory;
file= file.resolvePath("Preferences/version.txt");
if(file.exists)
{
checkVersion();
}
else
{
firstRun(); // create the version file.
}
}
public function getApplicationVersion():Number
{
var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = appXML.namespace();
var versionnumber:Number =Number(appXML.ns::versionNumber);
return versionnumber;
}
private function checkVersion():void
{
var stream:FileStream= new FileStream();
stream.open(file,FileMode.READ);
var prevVersion:String = stream.readUTFBytes(stream.bytesAvailable);
stream.close();
if(Number(prevVersion)<currentVersion)
{
// if the versionnumber inside the file is older than the current version we go and run important code.
// like alternating the structure of tables inside the sqlite database file.
runImportantCode();
//after running the important code, we set the version to the currentversion.
saveFile(currentVersion);
}
}
private function firstRun():void
{
// at the first time, we set the file version to 0, so the important code will be executed.
var firstVersion:Number=0;
saveFile(firstVersion);
// we also run the checkversion so important code is run right after installing an update
//(and the version file doesn't exist before the update).
checkFirstRun();
}
private function saveFile(currentVersion:Number):void
{
var stream:FileStream=new FileStream();
stream.open(file,FileMode.WRITE);
stream.writeUTFBytes(String(currentVersion));
stream.close();
}
private function runImportantCode():void
{
// here goes important code.
// make sure you check if the important change previously has been made or not, because this code is run after each update.
}
Hope this helps.
Greets, J.
Some you need to store whether the user has agreed to the agreement or not. IF they haven't agreed, then show it.
One way to do this would be to store a value in a shared object. Another way to do this would be to use a remote service and store such data in a central repository. I assume you'll want the second; so you can do some form of tracking against the number of users using your app.
How to use multiple files upload in symfony? I'm not really
sure how to do it 'the symfony way'. I read How to handle File Uploads with Doctrine, but how upload many files?
I try use collection field type and add setFiles method to object model
public function setFiles($files)
{
$this->files = $files;
foreach ($files as $file) {
$file->setObject($this);
}
}
but have exception (this always worked for normal model without any files)
Fatal error: Call to undefined method
Symfony\Component\HttpFoundation\File\UploadedFile::setObject()
please help me.
UPDATED:
I use for main object second form with file, and...
$files = $this->getRequest()->files->get('val_image');
foreach($files as $file){
$foto = new Foto;
$foto->setFile($file);
$foto->setPremises($premises->getPremises());
$this->getEm()->persist($foto);
}
it's works :)
Maybe this plugin can help you:
https://github.com/caoimhin/Symfony-jQuery-File-Upload/blob/master/Resources/public/README.md