2

I am writing PHP directly inside a Phing build.xml file using adhoc-task.

The following does work but throws up console errors:

<adhoc-task name="foo"><![CDATA[

 define('WP_INSTALLING', true);

 require_once '${build.dir.wp}/wp-load.php';
 require_once '${build.dir.wp}/wp-admin/includes/upgrade.php';
 require_once '${build.dir.wp}/wp-includes/wp-db.php';

 $result = wp_install( 'title', 'admin', '[email protected]');

]]></adhoc-task>

The error: The adhoc class you defined must be an instance of phing.Task BUILD FAILED.The adhoc class you defined must be an instance of phing.Task

But it still works...

If I wrap the PHP in a class it doesn't work at all:

<adhoc-task name="foo"><![CDATA[

   class FooTest extends Task {
   //php code ....
   }
]]></adhoc-task>

The error: You must define at least one class for AdhocTaskdefTask.

What is the proper way to include PHP inside the build file (without having access to the php/phing/tasks folder)?

1 Answer 1

2

From test/etc/regression/299/build.xml:

<?xml version="1.0" encoding="utf-8"?>
<project name="test" default="main">

  <target name="main">
    <bar/>
  </target>

  <adhoc-task name="bar"><![CDATA[
      class BarTask extends Task {
          function main() {
              print("BarTask: success!\n");
          }
      }
  ]]></adhoc-task>

</project>
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks I did not notice <bar/> in the docs, the errors are gone, but now the problem is that it doesn't work at all, for example gist.github.com/3766989 , is there something simple I am missing?
use -verbose and -debug options on the CLI to see where it fails.
Thanks, the problem is with several globals varibales in the include files, as seen here, stackoverflow.com/questions/9136073/… . Is there any way to just run raw php outside a function using <adhoc-task>?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.