Advertisement:

Author Topic: [100% SOLVED] Info for _Conejo issue #2140 and #2131 user alerts  (Read 1617 times)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
After doing the modifications ( https://github.com/osclass/Osclass/commit/17ca0114d4905ebaae6ca12ea8915c6701521b78 ), my dashboard wasn't working anymore..... so I rolled all code back.

I made only this modification https://github.com/osclass/Osclass/pull/2138/commits/00b9158aebafc7c33392e4e1a4d2f654c31fe3cf?diff=unified

I use osclass 3.7.1.

The  discussion: https://github.com/osclass/Osclass/issues/2131


How can I put in user-alerts 'Alert key word' instead of 'Alert 1' 'Alert 2' etc.? Thank you.
« Last Edit: April 28, 2017, 05:43:58 pm by marius-ciclistu »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Info for _Conejo issue #2140 and #2131 user alerts
« Reply #1 on: April 26, 2017, 04:02:06 am »
The 2nd modification you suggest is not a proper fix, are you sure that you applied it properly? All the changes are tested multiple times (and new version is practically ready to be released). Re-download master branch and perform a fresh install, you will see that everything works fine.

About last question, there's a nice plugin @ market (not free, and yes, I'm the author), that can do that and then some.

Regards

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Info for _Conejo issue #2140 and #2131 user alerts
« Reply #2 on: April 26, 2017, 10:11:45 am »
The 2nd modification you suggest is not a proper fix, are you sure that you applied it properly? All the changes are tested multiple times (and new version is practically ready to be released). Re-download master branch and perform a fresh install, you will see that everything works fine.

About last question, there's a nice plugin @ market (not free, and yes, I'm the author), that can do that and then some.

Regards

Thank you.

Well I did not suggest it, I just found it online.  I'll retry making the modifs from first link and come back with an answear.

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Info for _Conejo issue #2140 and #2131 user alerts
« Reply #3 on: April 26, 2017, 10:20:11 am »
If the discussion is already in github https://github.com/osclass/Osclass/issues/2131or https://github.com/osclass/Osclass/pull/2140, please continue it there. DO NOT open a new thread in an unrelated place (this) because the participants could not see it and miss it.

As explained https://github.com/osclass/Osclass/pull/2140 the fix you made broke more things than it fixes, so please do not use that fix.


If you have issues with the official / correct fix, then you could share them in those threads, or even here, but please, explain your issue. "dashboard broken" doesn't actually allow us to help you. Enable PHP debug https://doc.osclass.org/Debug_PHP_errors and share with us the underlying issue.

The "official" fix was tested and it's working fine, the fix you ended up doing, seems to fix it (it doesn't), but it break alerts for non registered users.

Also, we do not recommend cherry-picking some modifications and applying them to your website. If you want to have the latest development, please use the full hotfixes branch instead of selected modifications.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Info for _Conejo issue #2140 and #2131 user alerts
« Reply #4 on: April 26, 2017, 10:26:20 am »
I remade 2 times the modifs from https://github.com/osclass/Osclass/commit/17ca0114d4905ebaae6ca12ea8915c6701521b78

Something is not ok. My dashboard is all white when I hit refreash page after making the modifs.....

error:
[26-Apr-2017 09:20:26 Europe/Bucharest] PHP Parse error:  syntax error, unexpected 'if' (T_IF) in /oc-includes/osclass/alerts.php on line 79
 if($alert['fk_i_user_id']!=0) { 

(i removed the modificaton from model/Alerts.php)
« Last Edit: April 26, 2017, 10:30:45 am by marius-ciclistu »

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Info for _Conejo issue #2140 and #2131 user alerts
« Reply #5 on: April 26, 2017, 10:35:05 am »
I remade 2 times the modifs from https://github.com/osclass/Osclass/commit/17ca0114d4905ebaae6ca12ea8915c6701521b78

Something is not ok. My dashboard is all white when I hit refreash page after making the modifs.....

error:
[26-Apr-2017 09:20:26 Europe/Bucharest] PHP Parse error:  syntax error, unexpected 'if' (T_IF) in /oc-includes/osclass/alerts.php on line 79
 if($alert['fk_i_user_id']!=0) { 


(i removed the modificaton from model/Alerts.php)

Please look in previous lines (78, 77, 76, ...) something is not right, probably a missing semicolon ";" on some line, or an opened parentesis that's not closed ...

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Info for _Conejo issue #2140 and #2131 user alerts
« Reply #6 on: April 26, 2017, 10:55:52 am »
This is the initial code:

Code: [Select]
<?php
/*
 * Copyright 2014 Osclass
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

    
function osc_runAlert($type null$last_exec null) {
        if ( !
in_array($type, array('HOURLY''DAILY''WEEKLY''INSTANT')) ) {
            return;
        }

        if(
$last_exec==null) {
            
$cron Cron::newInstance()->getCronByType($type);
            if( 
is_array($cron) ) {
                
$last_exec $cron['d_last_exec'];
            } else {
                
$last_exec '0000-00-00 00:00:00';
            }
        }

        
$internal_name 'alert_email_hourly';
        switch (
$type) {
            case 
'HOURLY':
                
$internal_name 'alert_email_hourly';
            break;
            case 
'DAILY':
                
$internal_name 'alert_email_daily';
            break;
            case 
'WEEKLY':
                
$internal_name 'alert_email_weekly';
            break;
            case 
'INSTANT':
                
$internal_name 'alert_email_instant';
            break;
        }

        
$active   TRUE;
        
$searches Alerts::newInstance()->findByTypeGroup($type$active);


        foreach(
$searches as $s_search) {
            
// Get if there're new ads on this search
            
$json             $s_search['s_search'];
            
$array_conditions = (array)json_decode($json);

            
$new_search Search::newInstance();
            
$new_search->setJsonAlert($array_conditions);

            
$new_search->addConditions(sprintf(" %st_item.dt_pub_date > '%s' "DB_TABLE_PREFIX$last_exec));

            
$items      $new_search->doSearch();
            
$totalItems $new_search->count();

            if( 
count($items) > ) {
                
// If we have new items from last check
                // Catch the user subscribed to this search
                
$users Alerts::newInstance()->findUsersBySearchAndType($s_search['s_search'], $type$active);

                if( 
count($users) > ) {
                    
$ads '';
                    foreach(
$items as $item) {
                        
$ads .= '<a href="'osc_item_url_ns($item['pk_i_id']).'">' $item['s_title'] . '</a><br/>';
                    }

                    foreach(
$users as $user) {
                        
$alert Alerts::newInstance()->findBySearchAndUser($s_search['s_search'], $user['pk_i_id']);
                        if(
count($alert)>0) {
                            
osc_run_hook('hook_'.$internal_name$user$ads$alert[0], $items$totalItems);
                            
AlertsStats::newInstance()->increase(date('Y-m-d'));
                        }
                    }
                }
            }
        }
    }

And this is the code that is giving the error:

Code: [Select]
<?php
/*
 * Copyright 2014 Osclass
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

    
function osc_runAlert($type null$last_exec null) {
        
$mUser User::newInstance();
        if ( !
in_array($type, array('HOURLY''DAILY''WEEKLY''INSTANT')) ) {
            return;
        }

        if(
$last_exec==null) {
            
$cron Cron::newInstance()->getCronByType($type);
            if( 
is_array($cron) ) {
                
$last_exec $cron['d_last_exec'];
            } else {
                
$last_exec '0000-00-00 00:00:00';
            }
        }

        
$internal_name 'alert_email_hourly';
        switch (
$type) {
            case 
'HOURLY':
                
$internal_name 'alert_email_hourly';
            break;
            case 
'DAILY':
                
$internal_name 'alert_email_daily';
            break;
            case 
'WEEKLY':
                
$internal_name 'alert_email_weekly';
            break;
            case 
'INSTANT':
                
$internal_name 'alert_email_instant';
            break;
        }

        
$active   TRUE;
        
$searches Alerts::newInstance()->findByTypeGroup($type$active);


        foreach(
$searches as $s_search) {
            
// Get if there're new ads on this search
            
$json             $s_search['s_search'];
            
$array_conditions = (array)json_decode($json);

            
$new_search Search::newInstance();
            
$new_search->setJsonAlert($array_conditions);

            
$new_search->addConditions(sprintf(" %st_item.dt_pub_date > '%s' "DB_TABLE_PREFIX$last_exec));

            
$items      $new_search->doSearch();
            
$totalItems $new_search->count();

            if( 
count($items) > ) {
                
// If we have new items from last check
                // Catch the user subscribed to this search
                
$alerts Alerts::newInstance()->findUsersBySearchAndType($s_search['s_search'], $type$active);

                if( 
count($alerts) > ) {
                    
$ads '';
                    foreach(
$items as $item) {
                        
$ads .= '<a href="'osc_item_url_ns($item['pk_i_id']).'">' $item['s_title'] . '</a><br/>';
                    }

                                        foreach(
$alerts as $alert) {
+                        
$user = array();
+                        if(
$alert['fk_i_user_id']!=0) {
+                            
$user $mUser->findByPrimaryKey($alert['fk_i_user_id']);
+                        }
+                        if(!isset(
$user['s_name'])) {
+                            
$user = array(
+                                
's_name' => $alert['s_email'],
+                                
's_email' => $alert['s_email']
+                            );
+                        }
                        if(
count($alert)>0) {
                            
osc_run_hook('hook_'.$internal_name$user$ads$alert$items$totalItems);
                            
AlertsStats::newInstance()->increase(date('Y-m-d'));
                        }
                    }
                }
            }
        }
    }


I opened alerts, user items and email change. After file modifs, i hit refresh. it works.  BUT the error still remains and if I go to dashboard it is all white.

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Info for _Conejo issue #2140 and #2131 user alerts
« Reply #7 on: April 26, 2017, 10:57:20 am »
Code: [Select]
+                        $user = array();
+                        if($alert['fk_i_user_id']!=0) {
+                            $user = $mUser->findByPrimaryKey($alert['fk_i_user_id']);
+                        }
+                        if(!isset($user['s_name'])) {
+                            $user = array(
+                                's_name' => $alert['s_email'],
+                                's_email' => $alert['s_email']
+                            );
+                        }

All those "+" should not be in the file

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Info for _Conejo issue #2140 and #2131 user alerts
« Reply #8 on: April 26, 2017, 10:59:05 am »
I'm sorry. You were right. When replacing

Code: [Select]
                    foreach($alerts as $alert) {
+                        $user = array();
+                        if($alert['fk_i_user_id']!=0) {
+                            $user = $mUser->findByPrimaryKey($alert['fk_i_user_id']);
+                        }
+                        if(!isset($user['s_name'])) {
+                            $user = array(
+                                's_name' => $alert['s_email'],
+                                's_email' => $alert['s_email']
+                            );
+                        }

The plusses were paste also. it workes now.
Problem solved.

Thank you.

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: [SOLVED] Info for _Conejo issue #2140 and #2131 user alerts
« Reply #9 on: April 26, 2017, 01:17:08 pm »
You have a "View", then "Raw" button, if you wish to see a plain-text version of the file (the original).

Regards

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: [SOLVED] Info for _Conejo issue #2140 and #2131 user alerts
« Reply #10 on: April 26, 2017, 08:36:16 pm »
You have a "View", then "Raw" button, if you wish to see a plain-text version of the file (the original).

Regards
Thank you.
It's a first for me to replace a block of code from there. It didn't cross my mind that those plusses wil be also copyed.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: SOLVED Info for _Conejo issue #2140 and #2131 user alerts
« Reply #11 on: April 28, 2017, 02:16:03 pm »
Hello. I just tested the alerts with a registered user and with a nonregistered user.
I posted a new ad and I waited the cron to do it's job. I received the email that a new add was posted, but no emails on neither of the email addreses that had alerts....

I use 3.7.1 and server hourly cron at 10 minutes.
The ad was posted at 13:00:55 and the cron ran at 13:10:00.

Also the alerts in admin panel don't disappear if the user has removed them. Details about this behavior here: https://forums.osclass.org/development/alerts-in-admin/msg132690/#msg132690

EDIT: I found this: https://forums.osclass.org/themes/email-alerts-on-search-not-working-on-osclass-version-3-5-1/
Acc. to this the emails for alerts are sent once a day.
I reset the cron daily on my server and the emails are sent both to unregistered and unregistered users.

Thank you.

« Last Edit: April 28, 2017, 05:44:20 pm by marius-ciclistu »