2

I have been building a module in PyroCMS and have made its structure. I am using Streams API to build forms and perform my actions and also performed a dummy install to check if everything looks ok. Then I went on modifying the contents of the dummy and completing my structure. However, in the details.php file, I made a change where I created a foreign key (relationship type of field, if u know the API jargon) to retrieve a field from another stream(the other stream being defined after my current stream) and now when I install the module, it shows 'Could not install the module' error, but I can see the module has been installed. I have tried to comment out the foreign key reference, but the problem still persists.

Here's my details.php file:

class Module_Employer extends Module {

public $version = '1.0';

public function info()
{
    return array(
        'name' => array(
            'en' => 'Employer'
        ),
        'description' => array(
            'en' => 'Module for Employer'
        ),
        'frontend' => true,
        'backend' => true,
        'menu' => 'content',
        'shortcuts' => array(
            'create' => array(
                'name' => 'Employer:new',
                'uri' => 'admin/employer/create',
                'class' => 'add'
            )
        )
    );
}



public function install()
{
    // We're using the streams API to
    // do data setup.
    $this->load->driver('Streams');

    $this->load->language('employer/emp');


    // Add streams
    if ( ! $this->streams->streams->add_stream(lang('Employer:employers'), 'employers', 'employer', null, 'This is the Employer Stream')) return false;
    if ( ! $this->streams->streams->add_stream(lang('Employer:company'), 'company', 'company', null, 'This is the Company Stream')) return false;
    if ( ! $this->streams->streams->add_stream(lang('Employer:job'), 'jobs', 'job', null, 'This is the Job Stream')) return false;

    // Fields for employers table
    $employer_fields = array(
        array(
            'name' => 'Name',
            'slug' => 'name',
            'namespace' => 'employer',
            'type' => 'text',
            'extra' => array('max_length' => 100),
            'assign' => 'employers',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),
        array(
            'name' => 'Username',
            'slug' => 'username',
            'namespace' => 'employer',
            'type' => 'text',
            'extra' => array('max_length' => 100),
            'assign' => 'employers',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),
        array(
            'name' => 'Password',
            'slug' => 'password',
            'namespace' => 'employer',
            'type' => 'encrypt',
            'extra' => array('hide_typing' => 'yes'),
            'assign' => 'employers',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),
        array(
            'name' => 'Credits',
            'slug' => 'credits',
            'namespace' => 'employer',
            'type' => 'integer',
            'extra' => array('max_length' => 10),
            'assign' => 'employers',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),  
        array(
            'name' => 'Company name',
            'slug' => 'company_name',
            'namespace' => 'employer',
            'type' => 'relationship',
            'extra' => array('choose_stream' => 'company'),
            'assign' => 'employers',
            'title_column' => true,
            'required' => false,
            'unique' => false
        )
    );
    $this->streams->fields->add_fields($employer_fields);

    //Fields for company stream
    $company_fields = array(
        array(
            'name' => 'Username',
            'slug' => 'username',
            'namespace' => 'company',
            'type' => 'relationship',
            'extra' => array('choose_stream' => 'employers'),
            'assign' => 'company',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'E-mail',
            'slug' => 'email',
            'namespace' => 'company',
            'type' => 'email',
            'assign' => 'company',
            'title_column' => true,
            'required' => true,
            'unique' => false
        ),
        array(
            'name' => 'Company Name',
            'slug' => 'company_name',
            'namespace' => 'company',
            'type' => 'text',
            'extra' => array('max_length' => 100),
            'assign' => 'company',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),
        array(
            'name' => 'Logo',
            'slug' => 'logo',
            'namespace' => 'company',
            'type' => 'image',
            'extra' => array('folder' => 'upload'),
            'assign' => 'company',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
        'name' => 'Designation',
        'slug' => 'designation',
        'namespace' => 'company',
        'type' => 'text',
        'extra' => array('max_length' => 100),
        'assign' => 'company',
        'title_column' => true,
        'required' => false,
        'unique' => false
        ),
        array(
        'name' => 'Contact No.1',
        'slug' => 'contact1',
        'namespace' => 'company',
        'type' => 'integer',
        'extra' => array('max_length' => 10),
        'assign' => 'company',
        'title_column' => true,
        'required' => true,
        'unique' => false
        ),
        array(
        'name' => 'Contact No.2',
        'slug' => 'contact2',
        'namespace' => 'company',
        'type' => 'integer',
        'extra' => array('max_length' => 10),
        'assign' => 'company',
        'title_column' => true,
        'required' => false,
        'unique' => false
        ),
        array(
        'name' => 'Contact No.3',
        'slug' => 'contact3',
        'namespace' => 'company',
        'type' => 'integer',
        'extra' => array('max_length' => 10),
        'assign' => 'company',
        'title_column' => true,
        'required' => false,
        'unique' => false
        ),
        array(
        'name' => 'Address',
        'slug' => 'address',
        'namespace' => 'company',
        'type' => 'textarea',
        'assign' => 'company',
        'title_column' => true,
        'required' => true,
        'unique' => false
        ),
        array(
        'name' => 'Billing ddress',
        'slug' => 'billing_address',
        'namespace' => 'company',
        'type' => 'textarea',
        'assign' => 'company',
        'title_column' => true,
        'required' => true,
        'unique' => false
        ),
    );
    $this->streams->fields->add_fields($company_fields);

    //Fields for company stream
    $job_desc_fields = array(
        array(
            'name' => 'Username',
            'slug' => 'username',
            'namespace' => 'company',
            'type' => 'relationship',
            'extra' => array('choose_stream' => 'employers'),
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Key Skills',
            'slug' => 'keyskills',
            'namespace' => 'company',
            'type' => 'textarea',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => true,
            'unique' => false
        ),
        array(
            'name' => 'Position Summary',
            'slug' => 'position_summary',
            'namespace' => 'company',
            'type' => 'textarea',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Experience',
            'slug' => 'experience',
            'namespace' => 'company',
            'type' => 'text',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => true,
            'unique' => false
        ),
        array(
            'name' => 'Industry',
            'slug' => 'industry',
            'namespace' => 'company',
            'type' => 'text',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Functional Area',
            'slug' => 'functional_area',
            'namespace' => 'company',
            'type' => 'text',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Salary',
            'slug' => 'salary',
            'namespace' => 'company',
            'type' => 'text',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Start Date',
            'slug' => 'start_date',
            'namespace' => 'company',
            'type' => 'datetime',
            'assign' => 'jobs',
            'extra' => array('input_type' => 'datepicker'),
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Job Type',
            'slug' => 'job_type',
            'namespace' => 'company',
            'type' => 'choice',
            'assign' => 'jobs',
            'extra' => array('input_type' => 'datepicker'),
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
    );
    return true;
}

public function uninstall()
{
    $this->load->driver('Streams');

    $this->streams->utilities->remove_namespace('employer');

    return true;
}

public function upgrade($old_version)
{
    // Your Upgrade Logic
    return true;
}

public function help()
{
    // Return a string containing help info
    // You could include a file and return it here.
    return "No documentation has been added for this module.<br />Contact the module developer for assistance.";
}

}

1 Answers1

1

I had earlier "installed" the module, but under the uninstall() function, I forgot to add the code for removing all the streams(P.S: I had 3 streams with separate namespaces defined in the install() function). I only had the following:

$this->streams->utilities->remove_namespace('employer');

Due to this, the other streams were 'existing' in the system although on the face of it, the module was uninstalled, and whenever I tried to reinstall the module, I got the error Could not install module, since while creating tables/streams in the database, the query returned FALSE as the tables already existed.

However, I then added the code to remove all the other streams, by simply including their namespaces in the call for example:

$this->streams->utilities->remove_namespace('employer');
$this->streams->utilities->remove_namespace('job');
$this->streams->utilities->remove_namespace('company');

..and the problem was fixed!

j0k
  • 22,600
  • 28
  • 79
  • 90