mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-16 03:29:34 +00:00
BugFix
This commit is contained in:
@@ -290,8 +290,40 @@ class MessageLib
|
||||
return $result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/**
|
||||
* generateToken() - generates a new token for reading Messages from external
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function generateToken($length = 64)
|
||||
{
|
||||
// For PHP 7 you can use random_bytes()
|
||||
if(function_exists('random_bytes'))
|
||||
{
|
||||
$token = base64_encode(random_bytes($length));
|
||||
//base64 is about 33% longer, so we need to truncate the result
|
||||
return strtr(substr($token, 0, $length), '+/=', '-_,');
|
||||
}
|
||||
|
||||
// for PHP >=5.3 and <7
|
||||
if(function_exists('openssl_random_pseudo_bytes'))
|
||||
{
|
||||
$token = base64_encode(openssl_random_pseudo_bytes($length, $strong));
|
||||
// is the token strong enough?
|
||||
if($strong == true)
|
||||
return strtr(substr($token, 0, $length), '+/=', '-_,');
|
||||
}
|
||||
|
||||
//fallback to mt_rand if php < 5.3 or no openssl available
|
||||
$characters = '0123456789';
|
||||
$characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+';
|
||||
$charactersLength = strlen($characters)-1;
|
||||
$token = '';
|
||||
//select some random characters
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
$token .= $characters[mt_rand(0, $charactersLength)];
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -342,4 +374,4 @@ class MessageLib
|
||||
'msg' => lang('message_'.$error)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,20 +2,13 @@
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Migration_Message extends CI_Migration {
|
||||
class Migration_Message extends CI_Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
if (! $this->db->table_exists('public.tbl_msg_message'))
|
||||
{
|
||||
$this->db->insert('system.tbl_berechtigung', array(
|
||||
'berechtigung_kurzbz' => 'basis/message',
|
||||
'beschreibung' => 'Nachrichtensystem von FH-Complete'));
|
||||
$this->db->insert('system.tbl_rolleberechtigung', array(
|
||||
'berechtigung_kurzbz' => 'basis/message',
|
||||
'rolle_kurzbz' => 'admin',
|
||||
'art' => 'suid'));
|
||||
|
||||
$query= "
|
||||
CREATE TABLE public.tbl_msg_message (
|
||||
message_id serial,
|
||||
@@ -90,8 +83,6 @@ class Migration_Message extends CI_Migration {
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->db->delete('system.tbl_rolleberechtigung', array('berechtigung_kurzbz' => 'basis/message'));
|
||||
$this->db->delete('system.tbl_berechtigung', array('berechtigung_kurzbz' => 'basis/message'));
|
||||
$this->dbforge->drop_table('public.tbl_msg_recipient');
|
||||
$this->dbforge->drop_table('public.tbl_msg_status');
|
||||
$this->dbforge->drop_table('public.tbl_msg_attachment');
|
||||
|
||||
@@ -8,11 +8,17 @@ class Seed_Message
|
||||
public function __construct()
|
||||
{
|
||||
$this->fhc =& get_instance();
|
||||
$this->fhc->load->library('MessageLib');
|
||||
}
|
||||
|
||||
public function seed($limit = 25)
|
||||
public function seed($limit = 50)
|
||||
{
|
||||
echo "Seeding $limit messages ";
|
||||
// fetch some persons
|
||||
$db = $this->fhc->db->query('SELECT person_id FROM public.tbl_person LIMIT 100;');
|
||||
$person = $db->result();
|
||||
$num_persons = $db->num_rows();
|
||||
|
||||
for ($i = 0; $i < $limit; $i++)
|
||||
{
|
||||
echo ".";
|
||||
@@ -21,7 +27,7 @@ class Seed_Message
|
||||
(
|
||||
'subject' => $this->fhc->faker->sentence(4, true),
|
||||
'body' => $this->fhc->faker->text(400),
|
||||
'person_id' => $i%5+1
|
||||
'person_id' => $person[$i%$num_persons]->person_id
|
||||
);
|
||||
$this->fhc->db->insert('public.tbl_msg_message', $data);
|
||||
$message_id = $this->fhc->db->insert_id();
|
||||
@@ -29,14 +35,13 @@ class Seed_Message
|
||||
$data = array
|
||||
(
|
||||
'message_id' => $message_id,
|
||||
'person_id' => $i%5+2,
|
||||
'person_id' => $person[$i%($num_persons-1)+1]->person_id,
|
||||
'token' => $this->fhc->messagelib->generateToken(),
|
||||
'insertvon' => 'seed'
|
||||
);
|
||||
$recipient = $this->fhc->db->insert('public.tbl_msg_recipient', $data);
|
||||
if (!$recipient)
|
||||
show_error($recipient);
|
||||
//for ($j=1; $j<10; $j++)
|
||||
// $this->fhc->Message_model->addRecipient($thread->retval, $i+$j+5);
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
|
||||
Reference in New Issue
Block a user