I have written below code in custom_notifications.install file.
When I am trying to enable that module its giving me error "The website encountered an unexpected error. Please try again later."
kindly help me with this.
function custom_notifications_schema() {
$schema['custom_notification_log'] = array(
'fields' => array(
'cnl' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'notification_type' => array('type' => 'varchar', 'length' => 64),
'notification_type_id' => array('type' => 'int', 'unsigned' => TRUE),
'uid' => array('type' => 'int', 'unsigned' => TRUE),
'viewed_on' => array('type' => 'int', 'unsigned' => TRUE),
)
);
return $schema;
}
A couple things to try:
1) Look at your dblog (Reports -> Recent log messages) for PHP errors providing more information.
2) Go to the Uninstall tab and see if your module is listed. If it is, then uninstall it, then attempt to re-install.
SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE. try removing the unsigned and not null keys for your cnl field
Related
Because of a long series of events, I thought I lost a site completely due to my hosting company losing a server. Anyway, I'm trying to get back into a site sitting on a server with a cpanel I cant get to and a WHM I cant get to. I only have access to the root dir via ftp. I was able to reset my admin password using the method here https://www.drupal.org/node/1556488
I meant to also clear the flood table, but deleted it instead with db_drop_table('flood');
So, now I am getting a MYSQL error when I try to login. So, given I only have access to running php scripts to interact with the SQL database, can anyone help me figure out how to rebuild the flood table via the drupal db_create_table() method?
Much appreciated! This has been a nightmare.
I was able to rebuild my flood table with a php file ran from the drupal install directory with this in it: Just type in the url mysite.com/myphpfile.php to run it.
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once DRUPAL_ROOT . '/includes/password.inc';
$schema = array();
$schema['flood'] = array(
'fields' => array(
'fid' => array(
'type' => 'int',
'length' => 11,
'not null' => TRUE,
),
'event' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'identifier' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'timestamp' => array(
'type' => 'int',
'length' => 11,
'not null' => TRUE,
),
'expiration' => array(
'type' => 'int',
'length' => 11,
'not null' => TRUE,
),
),
'primary key' => array('fid'),
);
db_create_table('flood', $schema['flood']);
print "Done. Please delete this file immediately!";
drupal_exit();
?>
I have installed SkaDate, but it's creating auth.php creating error. I am getting the error:
bruce attack account is locked.
Its having auth.php file for validating login details.
Although in MySQL database value for admin username and password same I enter then also getting this error.
SkaDate is a dating software package.
To remove this notification, go through $internal_c/lang/config.php file
find the code around line number 7469 this code looks something similar to this.
'try_number' =>
SK_ConfigDtoObject::__set_state(array(
'config_id' => '208',
'config_section_id' => '63',
'name' => 'try_number',
'value' => 5,
'presentation' => 'integer',
'description' => NULL,
'php_validation' => NULL,
'js_validation' => NULL,
)),
Here, set the value to zero, like
'try_number' =>
SK_ConfigDtoObject::__set_state(array(
'config_id' => '208',
'config_section_id' => '63',
'name' => 'try_number',
'value' => 0,
'presentation' => 'integer',
'description' => NULL,
'php_validation' => NULL,
'js_validation' => NULL,
)),
Also set the lock_stamp attribute to zero, like
'lock_stamp' =>
SK_ConfigDtoObject::__set_state(array(
'config_id' => '206',
'config_section_id' => '63',
'name' => 'lock_stamp',
'value' => 0,
'presentation' => 'integer',
'description' => NULL,
'php_validation' => NULL,
'js_validation' => NULL,
)
And the last step is, in the config table, search the config_section_id (here it's 63, see above code) and change the values of 'try_number' and 'lock_stamp' attributes to zero.
This should solve your problem....
I can't locate you in our database, so please let me know your Client IDs in SkaDate system. We are more than happy to help you with any issues we'll be glad to answer any of your questions. Just visit www.skadate.com and drop us a line.
How can I store a file in a drupal entity? I have a plublic key to associate to an user so I have created an APIuser entity but I don't know what kind of field give to the public key property
function api_user_schema() {
$schema['api_user'] = array(
'description' => 'The base table for api_user.',
'fields' => array(
'id' => array(
'description' => 'The primary identifier for an artwork.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'public_key' => array(
'description' => 'The primary identifier for the public key.',
'type' => ???,
'unsigned' => TRUE,
'not null' => TRUE,
)
'created' => array(
'description' =>
'The Unix timestamp when the api_user was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' =>
'The Unix timestamp when the api_user was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'unique keys' => array(
'id' => array('id')
),
'primary key' => array('id'),
);
return $schema;
}
What you've got there is the definition of a single database table; Drupal offers no layer on top of that for files, so if you want to store a file you'll have to do so manually.
The best example you can take is that of the core user entity. It defines the picture property, which is an ID referencing an entry in the file_managed table (incidentally this is how all permanent file storage is handled by Drupal core by default).
This is the schema definition for that db column (from user_schema()):
'picture' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => "Foreign key: {file_managed}.fid of user's picture.",
)
Which is very similar to what your definition will need to look like.
From there, have a look at the user_account_form() function (which defines the form element for the picture property), and the user_validate_picture() function, which will show you how to perform the file upload, save the file in the file_managed table, and change the submitted value for the picture field to the relevant file ID (so that it automatically gets saved against the entity).
You'll mostly be replicating the code from those two functions so it won't be that tricky.
A common task for me when I'm writing CakePHP applications is to type out an SQL file and write it into the database before running bake to generate some scaffolding. This is one of the very few gripes I have with CakePHP - doing this ties me into MySQL, and I'm wondering if there's a better way to do it through code. As an example, in some frameworks I can define the columns that my model uses along with the datatype and such, and then run a command through an admin interface to "build" the database based on what what's presented in the code. It will do this on whatever database is sitting behind the framework.
Is there a way for CakePHP 2.x can do something like this? I want to write out the database schema in my Model code and run a command like bake to automatically generate the tables and columns that I need. After diving into the cookbook docs, the _schema attribute seems to do what I want to do:
class Post{
public $_schema = array(
'title' => array('type'=>'text'),
'description' => array('type'=>'text'),
'author' => array('type'=>'text')
);
}
but there are no examples explaining what I would I do from there. Does the _schema attribute serve a different purpose? Any help would be appreciated!
not from your $_schema array itself. but creating and using a schema file schema.php in /APP/Config/Schema.
you can then run the bake command "cake schema create" which will then "Drop and create tables based on the schema file."
I might then look sth like this:
class YourSchema extends CakeSchema {
public $addresses = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary'),
'contact_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 10),
'type' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 2),
'status' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 2),
'email' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 50, 'collate' => 'utf8_unicode_ci', 'comment' => 'redundant', 'charset' => 'utf8'),
'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_unicode_ci', 'engine' => 'MyISAM')
)
// more tables...
}
I've built an application to run on the client side (JavaScript & HTML) which needs to access and updated data on a server. It has a schema which consists of 5 tables. I've defined exactly what they should look like in JSON. I want these to be available as a JSON service served from a Drupal module. I understand how to use drupal_json_output to provide the results. I just can't find a simple way to ensure the database table is created for them and then to add and remove items from it. I'd like to maintain Drupal's independence from the underlying database. I don't need any search functionality, forms functionality etc. I just want to use Drupal's Database Abstraction.
At the moment I've tried the following in my install file:
/**
* Implements hook_schema
*/
function rcsarooms_schema(){
$schema = array();
$schema['rcsarooms'] = array(
'description' => 'Stores the structured information about the rooms and staircases.',
'fields' => array(
'ID' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'description' => 'Primary Key: used in the URLs to identify the entity.'
),'Name' => array(
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
'description' => 'The name used for links in the navigation menues.'
),'ParentID' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'description' => 'The ID of the parent element or "Root" if this is a root element'
),'Type' => array(
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
'description' => 'page, staircase, house, room or special'
),'BathroomSharing' => array(
'type' => 'int',
'description' => 'The number of people the bathroom is shared with (0 for unknown)'
),'RentBand' => array(
'type' => 'int',
'description' => 'The ID of the rent band the room is in.'
),'Floor' => array(
'type' => 'int',
'description' => 'The floor number (0 is courtyard level).'
)
),
'primary key' => array('ID')
);
return $schema;
}
And the following in my module file:
/**
* Implements hook_menu
*/
function rcsarooms_menu(){
$items['rcsarooms'] = array(
'page callback' => 'rcsarooms_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items;
}
function rcsarooms_callback(){
drupal_json_output(db_query("SELECT * FROM {rcsarooms}"));
drupal_exit();
return;
}
This gives the following error when I attempt to navigate to rcsarooms:
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.rcsarooms' doesn't exist: SELECT * FROM {rcsarooms}; Array ( ) in rcsarooms_callback()
You're probably looking for hook_schema() which Drupal will use to create your custom tables when you install your module. It goes in the mymodule.install file.
The Schema API will tell you everything you need to know about data types etc.
For adding/removing items from the database use the db_insert(), db_update() and db_merge() functions