For my scheduler task, I want to delete all the existing data from repository before updating it, every time the scheduler runs. I am able to save and add new data from XML File using add().
class FunctionFetcherService {
public function fetchRoomandLesson() {
$path = 'http:abc.dll?type=room&content=xml';
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$roomRepository = $objectManager->get("School\\booking\\Domain\\Repository\\RoomsRepository");
$this->roomRepository->removeAll();
$xml = simplexml_load_file($path);
$json = json_encode($xml);
$xmlArray = json_decode($json, true);
$serialized_array = serialize($xmlArray);
$unserialized_array = unserialize($serialized_array);
An error occurs removeAll() called on Null. I also referred to the already asked question: use removeAll() in scheduler task but it does doe not work.
You create the repository as variable $roomRepository and then try to access it through $this->roomRepository. Changing $this->roomRepository to $roomRepository should fix the error.
You should create an Extbase CommandController as your scheduler task. All registered commands are available in the scheduler as well as CLI commands.
By using CommandControllers you can use the full extbase framework, such as dependency injections and validations.
Please note that CommandController command methods must be suffixed with Command just like the linked example.
Related
I need to execute workflow from command line that is already created using UI.
Already I have tried to invoke workflow by creating workflow instance.
the code shown below which is i was tried
XmlTextReader reader = new XmlTextReader("Workflow1.xml");
Console.WriteLine("Waiting for Workflow completion..");
WorkflowRuntime runtime = new WorkflowRuntime();
WorkflowInstance instance = runtime.CreateWorkflow(reader);
instance.Start();
but it shows the error message "xml tag is not framed well".
I have fully copied the workflow xaml content and pasted in Workflow1.xml file.
is there any other possibilities to achieve this.
Thanks in Advance.
It looks like you are using Windows Workflow 4, but you are trying to use the Windows Workflow 3 runtime to execute the workflow. I've got a white paper [1] on WF 4 that might be useful, but here's a snippet from that article that might be helpful. It uses the workflowInvoker class to execute the workflow. You can also use WorkflowApplication if you have long running workflows that need bookmarking capabilities.
Activity mathWF;
using (Stream mathXaml = File.OpenRead("Math.xaml"))
{
mathWF = ActivityXamlServices.Load(mathXaml);
}
var outputs = WorkflowInvoker.Invoke(mathWF,
new Dictionary<string, object> {
{ "operand1", 5 },
{ "operand2", 10 },
{ "operation", "add" } });
Assert.AreEqual<int>(15, (int)outputs["result"], "Incorrect result returned");
Developer's Introduction to Windows Workflow
I would like to regenerate crud for all my Entities from my controller once I enter specific url. The example below runs a command for only one Entity for demonstration purpose. When I navigate to the path '/reCrud', my browser will spin forever but the command never executes. What is quite interesting is that the same code, when I run 'cache:clear' instead, will run just fine.
<?php
namespace AdminBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class CrudController extends Controller
{
/**
* #Route("/reCrud")
*/
public function reCrudAction()
{
$kernel = $this->get('kernel');
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new StringInput('doctrine:generate:crud AdminBundle:Klient --overwrite --no-debug');
// You can use NullOutput() if you don't need the output
$output = new BufferedOutput();
$application->run($input, $output);
// return the output, don't use if you used NullOutput()
$content = $output->fetch();
// return new Response(""), if you used NullOutput()
return new Response($content);
}
}
Perhaps this is only an environment configuration issue. Feel free to chunk that code and test it on your machine. Let me know if it works or not.
It spins because underneath it is waiting for you to enter stuff:
Welcome to the Doctrine2 CRUD generator
This command helps you generate CRUD controllers and templates.
First, give the name of the existing entity for which you want to generate a CRUD
(use the shortcut notation like AcmeBlogBundle:Post)
The Entity shortcut name [AdminBundle:Klient]:
Solution:
Try adding -n option which is:
-n, --no-interaction Do not ask any interactive question
So in the end your command would be something like this:
doctrine:generate:crud --entity=AdminBundle:Klient --overwrite --no-debug --no-interaction
I have a C# program which build me a TFS build definition. I want to do the same code in a powershell script. So far, I have been able code the script which will create me a new build definition in TFS. However, I have trouble setting Process section of the build definition. I need to convert the below code in C# to powershell and all attemps I have made did not work.
//Set process parameters
var process = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);
//Set BuildSettings properties
BuildSettings settings = new BuildSettings();
settings.ProjectsToBuild = new StringList("$/Templates/Main/Service/application1");
settings.PlatformConfigurations = new PlatformConfigurationList();
settings.PlatformConfigurations.Add(new PlatformConfiguration("Any CPU", "Debug"));
process.Add("BuildSettings", settings);
buildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process);
First I loaded the assemblies I need to work with TFS. When I want to replicate the same C# code as,
var process = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);
I did following in PowerShell
$process = New-Object Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.
Above gave me an error saying "Constructor not found. Cannot find an appropriate constructor for type Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers"
I checked and there are no constructors for that. My question is what I am I doing wrong in writing the PowerShell script to achieve the same functionality as c# code. I am sure it's syntax error that I am doing and not aware of the correct way of doing it in PowerShell.
It would appear from your code snippet (and confirmed via MSDN) that the DeserializeProcessParameters is a static method on the WorkflowHelpers class. You would need to invoke it with the following syntax in PowerShell:
$process = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($buildDefinition.ProcessParameters)
It looks like the buildDefinition variable is declared earlier - so I just stuck a $ character on it to make it a legit PowerShell variable. Same thing with the process variable. I hope this helps!
I'm using a TransactionalEditingDomain to manage changes on my model. However, I have some problems in creating an empty model. I think that the problem is when I add the model to the model Resource (modelResource.getContents().add(model);), because it should be put within a transaction. Accordingly, I was trying to use the AddCommand to perform such operation, but I am not able to find a EStructuralFeature for the Resource's contents.
In other words, I would like to write something like:
Command cmd = AddCommand.create(editingDomain, modelResource, FEAT_CONTENTS, model);
commandStack.execute(cmd);
The problem is that I cannot find the FEAT_CONTENTS... does anybody have a suggestion?
I have found the "official" solution with using AddCommand on the Eclipse Forum of EMF:
Command cmd = new AddCommand(editingDomain, modelResource.getContents(), model);
commandStack.execute(cmd);
Since removing a root object is also non-trivial, the same approach can be used with RemoveCommand:
Command cmd = new RemoveCommand(editingDomain, modelResource.getContents(), model);
Finally, for completeness, you should also know that DeleteCommand (that also removes all references to the removed object) does not work on root objects at all.
I found a solution, but sincerely I do not like it:
commandStack.execute(new RecordingCommand(editingDomain) {
protected void doExecute() {
modelResource.getContents().add(model);
}
});
I am working with a plugin in symfony 1.4, and would like to add a listener for a task from another plugin. When the user does php symfony doctrine:build I want my plugin to run a task of its own. Where/how do I register the listener? I did not have any success with http://www.symfony-project.org/gentle-introduction/1_4/en/17-Extending-Symfony
Thank you!
Actually you can hook your code to any symfony task. Have a look at sfBaseTask::doRun method. Any task, when is executed, emits 2 events: command.pre_command and command.post_command.
Create a class to store you code, for example:
class toolkitEvents
{
static public function commandPostEventHook(sfEvent $event)
{
$task = $event->getSubject();
if ($task->getFullName() === 'doctrine:build')
{
//do stuff or call another task
}
}
and connect this method to a dispatcher when initializing your plugin:
class yourPluginConfiguration extends sfPluginConfiguration
{
public function initialize()
{
$this->dispatcher->connect('command.post_command', array('toolkitEvents', 'commandPostEventHook'));
}
I don't think there is a suitable event for this (like the cache clear one).
My suggestion would be either to accept that it needs to be two tasks, or if you use build that often, create a wrapper task to call one first then the other - doctrine:build is a good example of how to do this. Or a bash/batch script!