Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/admin/abstract/class-rop-model-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function set( $key, $value = '', $refresh = false ) {

$this->data[ $key ] = apply_filters( 'rop_set_key_' . $key, $value );

return update_option( $this->namespace, $this->data );
return update_option( $this->namespace, $this->data, false );
}


Expand Down
29 changes: 28 additions & 1 deletion includes/admin/class-rop-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class Rop_Logger {
*/
private $stream;

/**
* Holds the log namespace.
*
* @access private
* @var string $log_namespace Defaults 'rop_logs'.
*/
private $log_namespace = 'rop_logs';

/**
* Rop_Logger constructor.
* Instantiate the Logger with specified formatter and stream.
Expand All @@ -38,7 +46,7 @@ class Rop_Logger {
*/
public function __construct() {

$this->stream = new Rop_Log_Handler( 'rop_logs' );
$this->stream = new Rop_Log_Handler( $this->log_namespace );

}

Expand Down Expand Up @@ -230,4 +238,23 @@ public function is_status_error_necessary( $logs = array() ) {

}

/**
* Utility method to cleanup authenticated services.
*
* @access public
*
* @param int $cleanup_log_count Cleanup the log count.
* @return array<string, mixed>
*/
public function cleanup_logs( $cleanup_log_count = 1000 ) {
$logs = $this->stream->get_logs();

if ( count( $logs ) > $cleanup_log_count ) {
$logs = array_slice( $logs, 0, $cleanup_log_count );

update_option( $this->log_namespace, array_reverse( $logs ), false );
}

return $logs;
}
}
14 changes: 14 additions & 0 deletions includes/admin/class-rop-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,20 @@ private function add_account_bluesky( $data ) {
return $this->response->to_array();
}

/**
* API method called to cleanup logs.
*
* @access private
* @return array<string, mixed>
*/
private function cleanup_logs() {
$model = new Rop_Logger();
$this->response->set_code( '200' )
->set_data( $model->cleanup_logs() );

return $this->response->to_array();
}

/**
* Share API method.
*
Expand Down
2 changes: 0 additions & 2 deletions includes/admin/models/class-rop-services-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Rop_Services_Model extends Rop_Model_Abstract {
*/
private $accounts_namespace = 'active_accounts';


/**
* Utility method to clear authenticated services.
*
Expand Down Expand Up @@ -519,5 +518,4 @@ public function find_account( $account_id ) {

return false;
}

}
6 changes: 6 additions & 0 deletions includes/class-rop-i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ public static function get_labels( $key = '' ) {
'clear_btn' => __( 'Clear logs', 'tweet-old-post' ),
'no_logs' => __( 'No recent logs!', 'tweet-old-post' ),
'export_btn' => __( 'Export logs', 'tweet-old-post' ),
'cleanup' => array(
'cta' => __( 'Cleanup logs', 'tweet-old-post' ),
'title' => __( 'Cleanup logs', 'tweet-old-post' ),
'description' => __( 'This will remove older logs and keep only the most recent 1,000 logs. This helps improve performance and reduce stored data.', 'tweet-old-post' ),
'btn' => __( 'Cleanup now', 'tweet-old-post' ),
),
),
'general' => array(
'plugin_name' => __( 'Revive Social', 'tweet-old-post' ),
Expand Down
4 changes: 4 additions & 0 deletions vue/src/models/rop_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ export default new Vuex.Store({
case 'toggle_tracking':

break
case 'cleanup_logs':
state.page.logs = stateData;
state.cron_status.logs_number = stateData.length || 0;
break;
default:
Vue.$log.error('No state request for ', requestName);
}
Expand Down
4 changes: 2 additions & 2 deletions vue/src/vue-elements/accounts-tab-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div
v-if="twitter_warning"
class="toast toast-warning"
v-html="labels.twitter_warning"

Check warning on line 7 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

'v-html' directive can lead to XSS attack
/>
<div class="container">
<div
Expand Down Expand Up @@ -84,7 +84,7 @@
>
<div class="column col-12">
<p class="upsell">
<i class="fa fa-info-circle " /> <span v-html="labels.upsell_accounts" />

Check warning on line 87 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

'v-html' directive can lead to XSS attack
</p>
</div>
</div>
Expand Down Expand Up @@ -126,11 +126,11 @@
type: String
}
},
components: {

Check warning on line 129 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

The "components" property should be above the "props" property on line 121
SignInBtn,

Check warning on line 130 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

The "SignInBtn" component has been registered but not used
ServiceUserTile,
AddAccountTile,
WebhookAccountModal,

Check warning on line 133 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

The "WebhookAccountModal" component has been registered but not used
'vue_spinner': vue_spinner
},
data: function () {
Expand All @@ -142,7 +142,7 @@
labels: this.$store.state.labels.accounts,
upsell_link: ropApiSettings.upsell_link,
pro_installed: ropApiSettings.pro_installed,
postTimeout: ''
postTimeout: '',
}
},
computed: {
Expand Down Expand Up @@ -171,7 +171,7 @@
if (this.searchAccount){
all_accounts = this.filteredAccounts(all_accounts);
}
this.twitter_warning = twitter > 1;

Check warning on line 174 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

Unexpected side effect in "accounts" computed property
this.$log.info('All accounts: ', all_accounts);
this.$log.debug('Preloading: ', this.$store.state.hide_preloading);
this.accountsCount = Object.keys(all_accounts).length;
Expand All @@ -189,7 +189,7 @@
},
hasActiveAccountsLimitation: function () {
return !this.pro_installed && this.accountsCount >= 2 && this.checkLicense ;
}
},
},
mounted: function () {
if (0 === this.is_preloading) {
Expand Down
100 changes: 98 additions & 2 deletions vue/src/vue-elements/logs-tab-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
/>
{{ labels.clear_btn }}
</button>
<button
class="btn btn-secondary"
:class="logs_no <= 1000 ? 'd-none' : ''"
@click="openCleanupModal()"
>
<i
v-if="!is_loading"
class="fa fa-trash"
/>
<i
v-else
class="fa fa-spinner fa-spin"
/>
{{ labels.cleanup.cta }}
</button>
</div>
</div>
<div class="columns">
Expand Down Expand Up @@ -70,6 +85,32 @@
</div>
</template>
</div>
<div
class="modal rop-cleanup-modal"
:class="cleanupModalClass"
>
<div class="modal-overlay" />
<div class="modal-container">
<div class="modal-header">
<button
class="btn btn-clear float-right"
@click="closeCleanupModal()"
/>
<div class="modal-title h5">
{{ labels.cleanup.title }}
</div>
</div>
<div class="modal-body">
{{ labels.cleanup.description }}
</div>
<div class="modal-footer">
<button
class="btn btn-success"
@click="cleanupLogs()"
>{{ labels.cleanup.btn }}</button>
Comment thread
girishpanchal30 marked this conversation as resolved.
Outdated
</div>
</div>
</div>
</div>
</div>
</template>
Expand All @@ -86,6 +127,7 @@
is_loading: false,
labels: this.$store.state.labels.logs,
upsell_link: ropApiSettings.upsell_link,
cleanupModal: false,
Comment thread
girishpanchal30 marked this conversation as resolved.
Outdated
}
},
computed: {
Expand All @@ -95,6 +137,11 @@
logs_no: function () {
return this.$store.state.cron_status.logs_number;
},
cleanupModalClass: function() {
return {
'active': true === this.cleanupModal
}
}
Comment thread
girishpanchal30 marked this conversation as resolved.
Outdated
},
watch: {
logs_no: function () {
Expand Down Expand Up @@ -153,8 +200,34 @@
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}

},
openCleanupModal() {
this.cleanupModal = true;
},
closeCleanupModal() {
this.cleanupModal = false;
},
cleanupLogs: function() {
if (this.is_loading) {
this.$log.warn('Request in progress...Bail');
return;
}
this.is_loading = true;
this.$store.dispatch('fetchAJAXPromise', {
req: 'cleanup_logs',
data: {}
}).then(response => {
this.is_loading = false;
this.cleanupModal = false;
if (this.$parent.start_status === true) {
// Stop sharing process if enabled.
this.$parent.togglePosting();
}
}, error => {
this.is_loading = false;
Vue.$log.error('Got nothing from server. Prompt user to check internet connection and try again', error)
})
},
Comment thread
girishpanchal30 marked this conversation as resolved.
Outdated
},
}
</script>
Expand Down Expand Up @@ -208,4 +281,27 @@
background-color: #FBE8E8;
}
}
#rop_core .rop-cleanup-modal .modal-container{
max-width: 500px;
padding: 25px;
.modal-title, .modal-footer{
text-align: center;
}
.btn-success{
border:none;
background-color:#00a32a;
color: #fff;
padding: 0.5rem 1rem;
height: auto;
display: inline;
}
.btn-success:hover{
background-color:#009528;
}
.modal-body{
font-size: 0.7rem;
margin: 10px 30px;
padding: 0px;
}
}
</style>
Loading