Question

I am creating a plugin for a WP site and I have to make an initial import of a huge amount of files from another directory. (The plugin is working well, etc etc.) I want to run the import using command line. Everything is OK if executing on local (Windows), but when I execute from Linux bash the defined constants are not evaluated but printed as a string.

define("ASCOR_RECORDINGS_TBL", $wpdb->prefix . "recordings");

Is there any setting I have to make to enable evaluation of PHP defined constants? My website is running on Dreamhost server.

When I execute the folowing line:

[myserver]$ /usr/local/php5/bin/php /home/path/to/import.php

I get:

WordPress database error Table 'db_ro.ASCOR_RECORDINGS_TBL' doesn't exist for query INSERT INTO `ASCOR_RECORDINGS_TBL` ...........

The content of the file I execute:

<?php
require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/wp-load.php";

require_once "class/AscorDbHelper.php";


$origin = realpath("/path/to/files");

$upload_dir = wp_upload_dir();
$subdir = $upload_dir['subdir'];


mkdir(ASCOR_UPLOAD_DIR . "/" . $subdir, 777, true);

require_once $origin . "/classes/PConfFiles.inc.php";

$db = new AscorDbHelper();

$cf = new PConfFiles('/^PC_([0-9\-]+)_(.*)\.([a-z0-9]{2,4})$/i', $origin);
$list = $cf->getFilesList();

$catPC = $db->addCategory("Special");
$catOther = $db->addCategory("Other");

if($list){
    $pc = $db->addAuthor("Ciprian V.");

    foreach($list as $rec){
        $fileUrl = $subdir . "/" . $rec[0];
        $desc = str_replace("-", " ", $rec[2]);

        copy(realpath($origin . "/" . $rec[0]), ASCOR_UPLOAD_DIR . "/" . $fileUrl );

        $db->addRecording($fileUrl, $catPC->id, $pc->id, $desc, null, $rec[1]);

        echo "Added: " . $rec[0] . "\n";
    }
}


$cf = new PConfFiles('/^([0-9\-]+)\_([^\_]+)_(.*)\.([a-z0-9]{2,4})$/i', $origin);
$list = $cf->getFilesList();

if($list){
    foreach($list as $rec){
        $authorName = str_replace("-", " ", $rec[2]);
        $date = $rec[1];
        $desc = str_replace("-", " ", $rec[3]);
        $fileUrl = $subdir . "/" . $rec[0];

        $authorId = $db->getAuthorIdOrSaveIt($authorName);

        copy(realpath($origin . "/" . $rec[0]), ASCOR_UPLOAD_DIR . "/" . $fileUrl );

        $db->addRecording($fileUrl, $catOther->id, $authorId, $desc, null, $date);

        echo "Added: " . $rec[0] . "\n";
    }
}

echo "done";

The constants are defined in the main file of the plugin:

define("ASCOR_RECORDINGS_TBL", $wpdb->prefix . "recordings");
define("ASCOR_RECORDINGS_AUTHORS_TBL", $wpdb->prefix . "recordings_authors");
define("ASCOR_RECORDINGS_CATEGORIES_TBL", $wpdb->prefix . "recordings_categories");

define("ASCOR_RECORDS_PER_PAGE", 50);

define("ASCOR_EXTEND_DIR", dirname(__FILE__));
define("ASCOR_EXTEND_URL", plugins_url("", __FILE__));

define("ASCOR_NOTIFY_UPDATED", "updated");
define("ASCOR_NOTIFY_ERROR", "error");

define("ASCOR_UPLOAD_DIR", ABSPATH . "/wp-content/uploads/recordings");
Was it helpful?

Solution

Is the file loaded? Introduce a parse error into it and see if it fails. And try it on Windows too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top